diff --git a/lib/sendcloud/sendcloud.class.php b/lib/sendcloud/sendcloud.class.php index 8bce0a1b48..b4656fbb59 100644 --- a/lib/sendcloud/sendcloud.class.php +++ b/lib/sendcloud/sendcloud.class.php @@ -18,12 +18,29 @@ class sendcloud public $Subject = ''; //Compatible phpmailer. public $nickNames = ''; + /** + * Set from. + * + * @param string $from + * @param string $fromname + * @access public + * @return void + */ public function setFrom($from, $fromname = '') { $this->from = $from; $this->fromname = empty($fromname) ? $from : $fromname; } + /** + * Add an address + * + * @param string $kind + * @param string $address + * @param string $name + * @access public + * @return bool + */ public function addAnAddress($kind, $address, $name = '') { $kind = strtolower($kind); @@ -42,6 +59,12 @@ class sendcloud return true; } + /** + * Send mail + * + * @access public + * @return bool + */ public function send() { if(!empty($this->Subject) and empty($this->subject)) $this->subject = $this->Subject; @@ -50,12 +73,8 @@ class sendcloud $param['nickNames'] = $this->nickNames; $param['subject'] = $this->subject; $param['content'] = $this->content; - $param['signature'] = $this->getSignature($param); - $data = http_build_query($param); - $result = file_get_contents($this->url . '?' . $data); - - $result = json_decode($result); + $result = $this->querySendcloud($this->url, $param); if($result->result == false) { throw new Exception($result->message . "(code:{$result->statusCode})"); @@ -63,6 +82,89 @@ class sendcloud } } + /** + * Get member list. + * + * @access public + * @return array + */ + public function memberList() + { + $url = 'http://api.notice.sendcloud.net/linkmanMember/list'; + $param['accessKey'] = $this->accessKey; + + $result = $this->querySendcloud($url, $param); + if($result->result == false) + { + throw new Exception($result->message . "(code:{$result->statusCode})"); + return false; + } + $members = array(); + foreach($result->info->linkmanMembers as $member) $members[$member->nickName] = $member; + + return $members; + } + + /** + * Add member + * + * @param object $member + * @access public + * @return object + */ + public function addMember($member) + { + $url = 'http://api.notice.sendcloud.net/linkmanMember/add'; + $param['accessKey'] = $this->accessKey; + $param['nickName'] = $member->nickName; + $param['email'] = $member->email; + if(isset($member->userName)) $param['userName'] = $member->userName; + if(isset($member->phone)) $param['phone'] = $member->phone; + + return $this->querySendcloud($url, $param); + } + + /** + * Delete member. + * + * @param string $nickName + * @access public + * @return object + */ + public function deleteMember($nickName) + { + $url = 'http://api.notice.sendcloud.net/linkmanMember/remove'; + $param['accessKey'] = $this->accessKey; + $param['nickName'] = $nickName; + + return $this->querySendcloud($url, $param); + } + + /** + * Query Sendcloud + * + * @param string $url + * @param array $param + * @access public + * @return object + */ + public function querySendcloud($url, $param) + { + if(!isset($param['signature'])) $param['signature'] = $this->getSignature($param); + + $data = http_build_query($param); + $result = file_get_contents($url . '?' . $data); + + return json_decode($result); + } + + /** + * Compute Signature. + * + * @param array $param + * @access public + * @return string + */ public function getSignature($param) { ksort($param); @@ -71,21 +173,50 @@ class sendcloud return md5($this->secretKey . '&' . $data . $this->secretKey); } + /** + * Add address + * + * @param string $address + * @param string $name + * @access public + * @return bool + */ public function addAddress($address, $name = '') { return $this->AddAnAddress('to', $address, $name); } + /** + * Add cc. + * + * @param string $address + * @param string $name + * @access public + * @return bool + */ public function addCC($address, $name = '') { return $this->AddAnAddress('cc', $address, $name); } + /** + * MsgHtml + * + * @param string $html + * @access public + * @return void + */ public function msgHtml($html) { $this->content = $html; } + /** + * Clear all recipients. + * + * @access public + * @return void + */ public function clearAllRecipients() { $this->to = ''; @@ -93,6 +224,12 @@ class sendcloud $this->replyto = ''; } + /** + * Clear attachments. + * + * @access public + * @return void + */ public function clearAttachments() { $this->subject = ''; @@ -102,6 +239,14 @@ class sendcloud $this->Subject = ''; } + /** + * Set language. + * + * @param string $langcode + * @param string $lang_path + * @access public + * @return bool + */ public function setLanguage($langcode = 'en', $lang_path = '../phpmailer/language/') { return true; diff --git a/module/group/lang/resource.php b/module/group/lang/resource.php index dc1635974f..7c7328f04b 100644 --- a/module/group/lang/resource.php +++ b/module/group/lang/resource.php @@ -547,8 +547,9 @@ $lang->resource->mail->test = 'test'; $lang->resource->mail->reset = 'reset'; $lang->resource->mail->browse = 'browse'; $lang->resource->mail->delete = 'delete'; -$lang->resource->mail->batchDelete = 'batchDelete'; -$lang->resource->mail->sendCloud = 'sendCloud'; +$lang->resource->mail->batchDelete = 'batchDelete'; +$lang->resource->mail->sendCloud = 'sendCloud'; +$lang->resource->mail->sendcloudUser = 'sendcloudUser'; $lang->mail->methodOrder[5] = 'index'; $lang->mail->methodOrder[10] = 'detect'; @@ -560,6 +561,7 @@ $lang->mail->methodOrder[35] = 'browse'; $lang->mail->methodOrder[40] = 'delete'; $lang->mail->methodOrder[45] = 'batchDelete'; $lang->mail->methodOrder[50] = 'sendCloud'; +$lang->mail->methodOrder[55] = 'sendcloudUser'; /* custom. */ $lang->resource->custom = new stdclass(); @@ -1091,3 +1093,4 @@ $lang->changelog['7.3'][] = 'productplan-batchEdit'; $lang->changelog['7.3'][] = 'admin-sso'; $lang->changelog['7.3'][] = 'cron-openProcess'; $lang->changelog['7.3'][] = 'mail-sendCloud'; +$lang->changelog['7.3'][] = 'mail-sendcloudUser'; diff --git a/module/mail/control.php b/module/mail/control.php index 79f75a4707..af1ddbf260 100755 --- a/module/mail/control.php +++ b/module/mail/control.php @@ -374,4 +374,67 @@ class mail extends control if($idList) $this->dao->delete()->from(TABLE_MAILQUEUE)->where('id')->in($idList)->exec(); die(js::reload('parent')); } + + /** + * Sendcloud user. + * + * @access public + * @return void + */ + public function sendcloudUser() + { + if($this->config->mail->mta != 'sendcloud') die(js::locate('back')); + + $this->mta = $this->mail->setMTA(); + if($_POST) + { + $data = fixer::input('post')->get(); + $action = $data->action; + $listName = $action == 'delete' ? 'syncedList' : 'unsyncList'; + + $users = array_unique($data->$listName); + if(empty($users)) die(js::reload('parent')); + + $realnameAndEmails = $this->loadModel('user')->getRealNameAndEmails($users); + $actionedEmail = array(); + foreach($realnameAndEmails as $realnameAndEmail) + { + $email = $realnameAndEmail->email; + if(isset($actionedEmail[$email])) continue; + + if($action == 'delete') + { + $result = $this->mta->deleteMember($email); + } + elseif($action == 'sync') + { + $member = new stdclass(); + $member->nickName = $email; + $member->email = $email; + $member->userName = $realnameAndEmail->realname; + + $result = $this->mta->addMember($member); + } + + if(!$result->result) + { + echo(js::alert($this->lang->mail->sendCloudFail . $result->message . "(CODE: $result->statusCode)")); + die(js::reload('parent')); + } + + $actionedEmail[$email] = $email; + } + + echo(js::alert($this->lang->mail->sendCloudSuccess)); + die(js::reload('parent')); + } + + $this->view->title = $this->lang->mail->sendcloudUser; + $this->view->position[] = html::a(inlink('index'), $this->lang->mail->common); + $this->view->position[] = $this->lang->mail->sendcloudUser; + + $this->view->members = $this->mta->memberList(); + $this->view->users = $this->loadModel('user')->getList(); + $this->display(); + } } diff --git a/module/mail/lang/en.php b/module/mail/lang/en.php index fcb6c13de1..7e4e155c5d 100755 --- a/module/mail/lang/en.php +++ b/module/mail/lang/en.php @@ -8,8 +8,9 @@ $lang->mail->test = 'Testing'; $lang->mail->reset = 'Reset'; $lang->mail->browse = 'Mail list'; $lang->mail->delete = 'Delete mail'; -$lang->mail->sendCloud = 'SendCloud'; -$lang->mail->batchDelete = 'Batch delete'; +$lang->mail->sendCloud = 'SendCloud'; +$lang->mail->batchDelete = 'Batch delete'; +$lang->mail->sendcloudUser = 'SendCloud Contact'; $lang->mail->turnon = 'Turnon'; $lang->mail->async = 'Asynchronous'; @@ -27,6 +28,11 @@ $lang->mail->charset = 'Charset'; $lang->mail->accessKey = 'accessKey'; $lang->mail->secretKey = 'secretKey'; +$lang->mail->syncedUser = 'Synced user'; +$lang->mail->unsyncUser = 'Unsync user'; +$lang->mail->sync = 'Sync'; +$lang->mail->remove = 'Remove'; + $lang->mail->toList = 'Addressee'; $lang->mail->subjectName = 'Subject'; $lang->mail->addedBy = 'Sender'; @@ -67,8 +73,10 @@ $lang->mail->sendmailTips = 'Tips: system will not send mail to current user.' $lang->mail->needConfigure = "I can not find the configuration, please configure it first."; $lang->mail->nofsocket = 'The fsocket correlation function is disabled, not letter! Please enlarge the setting of allow_url_fopen to On in php.ini and open the extension of openssl. Restart apache.'; $lang->mail->noOpenssl = 'Please open the extension of openssl when use tls. Restart apache.'; +$lang->mail->sendCloudFail = 'Fail. Reason:'; $lang->mail->sendCloudHelp = <<SendCloud Notice is SendCloud's team notification service. Can view to notice.sendcloud.net

accessKey and secretKey can go to the "Settings" page view after login. The sender name and address is also provided in the "Settings" page.

Letter, The nickname of Notice SendCloud contact must to be consistent with the email. You may not succeed in sending.

EOD; +$lang->mail->sendCloudSuccess = 'Success'; diff --git a/module/mail/lang/zh-cn.php b/module/mail/lang/zh-cn.php index b995e1d541..032b8eb46e 100755 --- a/module/mail/lang/zh-cn.php +++ b/module/mail/lang/zh-cn.php @@ -8,8 +8,9 @@ $lang->mail->test = '测试发信'; $lang->mail->reset = '重置'; $lang->mail->browse = '邮件列表'; $lang->mail->delete = '删除邮件'; -$lang->mail->sendCloud = 'SendCloud发信'; -$lang->mail->batchDelete = '批量删除'; +$lang->mail->sendCloud = 'SendCloud发信'; +$lang->mail->batchDelete = '批量删除'; +$lang->mail->sendcloudUser = 'SendCloud 联系人'; $lang->mail->turnon = '是否打开'; $lang->mail->async = '异步发送'; @@ -27,6 +28,11 @@ $lang->mail->charset = '编码'; $lang->mail->accessKey = 'accessKey'; $lang->mail->secretKey = 'secretKey'; +$lang->mail->syncedUser = '已经同步'; +$lang->mail->unsyncUser = '未同步'; +$lang->mail->sync = '同步'; +$lang->mail->remove = '移除'; + $lang->mail->toList = '收信人'; $lang->mail->subjectName = '主题'; $lang->mail->addedBy = '发送者'; @@ -67,8 +73,10 @@ $lang->mail->sendmailTips = '提示:系统不会为当前操作者发信。' $lang->mail->needConfigure = '无法找到邮件配置信息,请先配置邮件发送参数。'; $lang->mail->nofsocket = 'fsocket相关函数被禁用,不能发信!请在php.ini中修改allow_url_fopen为On,打开openssl扩展。 保存并重新启动apache。'; $lang->mail->noOpenssl = 'ssl和tls加密,请打开openssl扩展。 保存并重新启动apache。'; +$lang->mail->sendCloudFail = '操作失败,原因:'; $lang->mail->sendCloudHelp = <<Notice SendCloud是SendCloud的团队通知服务。具体可以到notice.sendcloud.net查看

-

accessKey和secretKey可以到登陆后的"设置"页面查看。发信人地址和名称也在"设置"页面设置。

-

发信时,Notice SendCloud联系人里面的昵称要跟邮箱一致。否则可能无法成功发信。

+

1、Notice SendCloud是SendCloud的团队通知服务。具体可以到notice.sendcloud.net查看

+

2、accessKey和secretKey可以到登陆后的"设置"页面查看。发信人地址和名称也在"设置"页面设置。

+

3、发信时,Notice SendCloud联系人里面的昵称要跟邮箱一致,否则无法成功发信。可以到[SendCloud 联系人]页面,将禅道用户同步到SendCloud联系人中

EOD; +$lang->mail->sendCloudSuccess = '操作成功'; diff --git a/module/mail/model.php b/module/mail/model.php index 2e48a302ce..e44cfb679d 100644 --- a/module/mail/model.php +++ b/module/mail/model.php @@ -168,6 +168,8 @@ class mailModel extends model $funcName = "set{$this->config->mail->mta}"; if(!method_exists($this, $funcName)) $this->app->triggerError("The MTA {$this->config->mail->mta} not supported now.", __FILE__, __LINE__, $exit = true); $this->$funcName(); + + return $this->mta; } /** diff --git a/module/mail/view/detect.html.php b/module/mail/view/detect.html.php index cdc2afa0af..2a3c6b41e6 100755 --- a/module/mail/view/detect.html.php +++ b/module/mail/view/detect.html.php @@ -18,7 +18,7 @@ include '../../common/view/header.html.php'; mail->common;?> mail->detect;?> -
mail->sendCloud, '', "class='btn btn-primary'")?>
+
app->getClientLang() != 'en') common::printLink('mail', 'sendCloud', '', $lang->mail->sendCloud, '', "class='btn btn-primary'")?>
diff --git a/module/mail/view/sendcloud.html.php b/module/mail/view/sendcloud.html.php index ace30320a3..0508479ef7 100755 --- a/module/mail/view/sendcloud.html.php +++ b/module/mail/view/sendcloud.html.php @@ -44,12 +44,13 @@ include '../../common/view/header.html.php'; config->mail->turnon and $mailExist) echo html::linkButton($lang->mail->test, inlink('test')); + if($this->config->mail->turnon and common::hasPriv('mail', 'sendcloudUser')) echo html::linkButton($lang->mail->sendcloudUser, inlink('sendcloudUser')); echo html::linkButton($lang->mail->reset, inlink('reset')); ?>
-
mail->sendCloudHelp?>
+
mail->sendCloudHelp, common::hasPriv('mail', 'sendcloudUser') ? inlink('sendcloudUser') : '#')?>
diff --git a/module/mail/view/sendclouduser.html.php b/module/mail/view/sendclouduser.html.php new file mode 100644 index 0000000000..6605c0f947 --- /dev/null +++ b/module/mail/view/sendclouduser.html.php @@ -0,0 +1,101 @@ + + * @package mail + * @version $Id$ + * @link http://www.zentao.net + */ +?> + +
+
mail->sendcloudUser?>
+
+
+
+
+
+
mail->unsyncUser?>
+ + + + + + + + + + $user):?> + email and isset($members[$user->email])) continue;?> + + + + + + + + + + + + + +
user->account;?> user->realname;?> user->email;?>
+ + account?> + realname?>email?>
+ mail->sync); + echo html::hidden('action', 'sync'); + ?> +
+
+
+
+
+
+
+
mail->syncedUser?>
+ + + + + + + + + + $user):?> + email) or !isset($members[$user->email])) continue;?> + + + + + + + + + + + + +
user->account;?> user->realname;?> user->email;?>
+ + account?> + realname?>email?>
+ mail->remove); + echo html::hidden('action', 'delete'); + ?> +
+
+
+
+
+ +