1 | <?php |
---|
2 | /*********************************************** |
---|
3 | * File : sendmail.php |
---|
4 | * Project : Z-Push |
---|
5 | * Descr : Provides the SENDMAIL, SMARTREPLY and SMARTFORWARD command |
---|
6 | * |
---|
7 | * Created : 16.02.2012 |
---|
8 | * |
---|
9 | * Copyright 2007 - 2012 Zarafa Deutschland GmbH |
---|
10 | * |
---|
11 | * This program is free software: you can redistribute it and/or modify |
---|
12 | * it under the terms of the GNU Affero General Public License, version 3, |
---|
13 | * as published by the Free Software Foundation with the following additional |
---|
14 | * term according to sec. 7: |
---|
15 | * |
---|
16 | * According to sec. 7 of the GNU Affero General Public License, version 3, |
---|
17 | * the terms of the AGPL are supplemented with the following terms: |
---|
18 | * |
---|
19 | * "Zarafa" is a registered trademark of Zarafa B.V. |
---|
20 | * "Z-Push" is a registered trademark of Zarafa Deutschland GmbH |
---|
21 | * The licensing of the Program under the AGPL does not imply a trademark license. |
---|
22 | * Therefore any rights, title and interest in our trademarks remain entirely with us. |
---|
23 | * |
---|
24 | * However, if you propagate an unmodified version of the Program you are |
---|
25 | * allowed to use the term "Z-Push" to indicate that you distribute the Program. |
---|
26 | * Furthermore you may use our trademarks where it is necessary to indicate |
---|
27 | * the intended purpose of a product or service provided you use it in accordance |
---|
28 | * with honest practices in industrial or commercial matters. |
---|
29 | * If you want to propagate modified versions of the Program under the name "Z-Push", |
---|
30 | * you may only do so if you have a written permission by Zarafa Deutschland GmbH |
---|
31 | * (to acquire a permission please contact Zarafa at trademark@zarafa.com). |
---|
32 | * |
---|
33 | * This program is distributed in the hope that it will be useful, |
---|
34 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
35 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
36 | * GNU Affero General Public License for more details. |
---|
37 | * |
---|
38 | * You should have received a copy of the GNU Affero General Public License |
---|
39 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
---|
40 | * |
---|
41 | * Consult LICENSE file for details |
---|
42 | ************************************************/ |
---|
43 | |
---|
44 | class SendMail extends RequestProcessor { |
---|
45 | |
---|
46 | /** |
---|
47 | * Handles the SendMail, SmartReply and SmartForward command |
---|
48 | * |
---|
49 | * @param int $commandCode |
---|
50 | * |
---|
51 | * @access public |
---|
52 | * @return boolean |
---|
53 | */ |
---|
54 | public function Handle($commandCode) { |
---|
55 | $status = SYNC_COMMONSTATUS_SUCCESS; |
---|
56 | $sm = new SyncSendMail(); |
---|
57 | |
---|
58 | $reply = $forward = $parent = $sendmail = $smartreply = $smartforward = false; |
---|
59 | if (Request::GetGETCollectionId()) |
---|
60 | $parent = Request::GetGETCollectionId(); |
---|
61 | if ($commandCode == ZPush::COMMAND_SMARTFORWARD) |
---|
62 | $forward = Request::GetGETItemId(); |
---|
63 | else if ($commandCode == ZPush::COMMAND_SMARTREPLY) |
---|
64 | $reply = Request::GetGETItemId(); |
---|
65 | |
---|
66 | if (self::$decoder->IsWBXML()) { |
---|
67 | $el = self::$decoder->getElement(); |
---|
68 | |
---|
69 | if($el[EN_TYPE] != EN_TYPE_STARTTAG) |
---|
70 | return false; |
---|
71 | |
---|
72 | |
---|
73 | if($el[EN_TAG] == SYNC_COMPOSEMAIL_SENDMAIL) |
---|
74 | $sendmail = true; |
---|
75 | else if($el[EN_TAG] == SYNC_COMPOSEMAIL_SMARTREPLY) |
---|
76 | $smartreply = true; |
---|
77 | else if($el[EN_TAG] == SYNC_COMPOSEMAIL_SMARTFORWARD) |
---|
78 | $smartforward = true; |
---|
79 | |
---|
80 | if(!$sendmail && !$smartreply && !$smartforward) |
---|
81 | return false; |
---|
82 | |
---|
83 | $sm->Decode(self::$decoder); |
---|
84 | } |
---|
85 | else { |
---|
86 | $sm->mime = self::$decoder->GetPlainInputStream(); |
---|
87 | // no wbxml output is provided, only a http OK |
---|
88 | $sm->saveinsent = Request::GetGETSaveInSent(); |
---|
89 | } |
---|
90 | // Check if it is a reply or forward. Two cases are possible: |
---|
91 | // 1. Either $smartreply or $smartforward are set after reading WBXML |
---|
92 | // 2. Either $reply or $forward are set after geting the request parameters |
---|
93 | if ($reply || $smartreply || $forward || $smartforward) { |
---|
94 | // If the mobile sends an email in WBXML data the variables below |
---|
95 | // should be set. If it is a RFC822 message, get the reply/forward message id |
---|
96 | // from the request as they are always available there |
---|
97 | if (!isset($sm->source)) $sm->source = new SyncSendMailSource(); |
---|
98 | if (!isset($sm->source->itemid)) $sm->source->itemid = Request::GetGETItemId(); |
---|
99 | if (!isset($sm->source->folderid)) $sm->source->folderid = Request::GetGETCollectionId(); |
---|
100 | |
---|
101 | // replyflag and forward flags are actually only for the correct icon. |
---|
102 | // Even if they are a part of SyncSendMail object, they won't be streamed. |
---|
103 | if ($smartreply || $reply) |
---|
104 | $sm->replyflag = true; |
---|
105 | else |
---|
106 | $sm->forwardflag = true; |
---|
107 | |
---|
108 | if (!isset($sm->source->folderid)) |
---|
109 | ZLog::Write(LOGLEVEL_ERROR, sprintf("No parent folder id while replying or forwarding message:'%s'", (($reply) ? $reply : $forward))); |
---|
110 | } |
---|
111 | |
---|
112 | self::$topCollector->AnnounceInformation(sprintf("Sending email with %d bytes", strlen($sm->mime)), true); |
---|
113 | |
---|
114 | try { |
---|
115 | $status = self::$backend->SendMail($sm); |
---|
116 | } |
---|
117 | catch (StatusException $se) { |
---|
118 | $status = $se->getCode(); |
---|
119 | $statusMessage = $se->getMessage(); |
---|
120 | } |
---|
121 | |
---|
122 | if ($status != SYNC_COMMONSTATUS_SUCCESS) { |
---|
123 | if (self::$decoder->IsWBXML()) { |
---|
124 | // TODO check no WBXML on SmartReply and SmartForward |
---|
125 | self::$encoder->StartWBXML(); |
---|
126 | self::$encoder->startTag(SYNC_COMPOSEMAIL_SENDMAIL); |
---|
127 | self::$encoder->startTag(SYNC_COMPOSEMAIL_STATUS); |
---|
128 | self::$encoder->content($status); //TODO return the correct status |
---|
129 | self::$encoder->endTag(); |
---|
130 | self::$encoder->endTag(); |
---|
131 | } |
---|
132 | else |
---|
133 | throw new HTTPReturnCodeException($statusMessage, HTTP_CODE_500, null, LOGLEVEL_WARN); |
---|
134 | } |
---|
135 | |
---|
136 | return $status; |
---|
137 | } |
---|
138 | } |
---|
139 | ?> |
---|