59177427 |
1 | <?php |
895905c0 |
2 | |
35586184 |
3 | /** |
4 | * compose.php |
5 | * |
35586184 |
6 | * This code sends a mail. |
7 | * |
8 | * There are 4 modes of operation: |
9 | * - Start new mail |
10 | * - Add an attachment |
11 | * - Send mail |
12 | * - Save As Draft |
13 | * |
47ccfad4 |
14 | * @copyright © 1999-2006 The SquirrelMail Project Team |
4b4abf93 |
15 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
30967a1e |
16 | * @version $Id$ |
8f6f9ba5 |
17 | * @package squirrelmail |
35586184 |
18 | */ |
f7fb20fe |
19 | |
30967a1e |
20 | /** |
202bcbcc |
21 | * Include the SquirrelMail initialization file. |
30967a1e |
22 | */ |
202bcbcc |
23 | require('../include/init.php'); |
86725763 |
24 | |
25 | /* SquirrelMail required files. */ |
202bcbcc |
26 | require_once(SM_PATH . 'functions/imap_general.php'); |
27 | require_once(SM_PATH . 'functions/imap_messages.php'); |
86725763 |
28 | require_once(SM_PATH . 'functions/date.php'); |
29 | require_once(SM_PATH . 'functions/mime.php'); |
86725763 |
30 | require_once(SM_PATH . 'class/deliver/Deliver.class.php'); |
24192f77 |
31 | require_once(SM_PATH . 'functions/addressbook.php'); |
df96b37a |
32 | require_once(SM_PATH . 'functions/forms.php'); |
a2b193bc |
33 | require_once(SM_PATH . 'functions/identity.php'); |
91f2085b |
34 | |
0b97a708 |
35 | /* --------------------- Get globals ------------------------------------- */ |
953fa718 |
36 | /** COOKIE VARS */ |
37 | sqgetGlobalVar('key', $key, SQ_COOKIE); |
0b97a708 |
38 | |
953fa718 |
39 | /** SESSION VARS */ |
40 | sqgetGlobalVar('username', $username, SQ_SESSION); |
41 | sqgetGlobalVar('onetimepad',$onetimepad, SQ_SESSION); |
42 | sqgetGlobalVar('base_uri', $base_uri, SQ_SESSION); |
43 | sqgetGlobalVar('delimiter', $delimiter, SQ_SESSION); |
44 | |
45 | sqgetGlobalVar('composesession', $composesession, SQ_SESSION); |
46 | sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION); |
81de00c0 |
47 | sqgetGlobalVar('delayed_errors', $delayed_errors, SQ_SESSION); |
48 | if (is_array($delayed_errors)) { |
49 | $oErrorHandler->AssignDelayedErrors($delayed_errors); |
50 | sqsession_unregister("delayed_errors"); |
51 | } |
953fa718 |
52 | |
53 | /** SESSION/POST/GET VARS */ |
b455793d |
54 | sqgetGlobalVar('session',$session); |
55 | sqgetGlobalVar('mailbox',$mailbox); |
1e2a6ff6 |
56 | if(!sqgetGlobalVar('identity',$identity)) { |
57 | $identity=0; |
58 | } |
edd82fcf |
59 | sqgetGlobalVar('send_to',$send_to); |
60 | sqgetGlobalVar('send_to_cc',$send_to_cc); |
61 | sqgetGlobalVar('send_to_bcc',$send_to_bcc); |
62 | sqgetGlobalVar('subject',$subject); |
63 | sqgetGlobalVar('body',$body); |
b455793d |
64 | sqgetGlobalVar('mailprio',$mailprio); |
65 | sqgetGlobalVar('request_mdn',$request_mdn); |
66 | sqgetGlobalVar('request_dr',$request_dr); |
67 | sqgetGlobalVar('html_addr_search',$html_addr_search); |
68 | sqgetGlobalVar('mail_sent',$mail_sent); |
69 | sqgetGlobalVar('passed_id',$passed_id); |
70 | sqgetGlobalVar('passed_ent_id',$passed_ent_id); |
71 | sqgetGlobalVar('send',$send); |
0b97a708 |
72 | |
b455793d |
73 | sqgetGlobalVar('attach',$attach); |
12a0ed01 |
74 | |
b455793d |
75 | sqgetGlobalVar('draft',$draft); |
76 | sqgetGlobalVar('draft_id',$draft_id); |
77 | sqgetGlobalVar('ent_num',$ent_num); |
78 | sqgetGlobalVar('saved_draft',$saved_draft); |
79 | sqgetGlobalVar('delete_draft',$delete_draft); |
a6d3eff6 |
80 | if ( sqgetGlobalVar('startMessage',$startMessage) ) { |
81 | $startMessage = (int)$startMessage; |
82 | } else { |
83 | $startMessage = 1; |
84 | } |
953fa718 |
85 | |
8780308f |
86 | |
953fa718 |
87 | /** POST VARS */ |
88 | sqgetGlobalVar('sigappend', $sigappend, SQ_POST); |
89 | sqgetGlobalVar('from_htmladdr_search', $from_htmladdr_search, SQ_POST); |
90 | sqgetGlobalVar('addr_search_done', $html_addr_search_done, SQ_POST); |
91 | sqgetGlobalVar('send_to_search', $send_to_search, SQ_POST); |
92 | sqgetGlobalVar('do_delete', $do_delete, SQ_POST); |
93 | sqgetGlobalVar('delete', $delete, SQ_POST); |
b0314f04 |
94 | sqgetGlobalVar('restoremessages', $restoremessages, SQ_POST); |
953fa718 |
95 | if ( sqgetGlobalVar('return', $temp, SQ_POST) ) { |
73ad81bf |
96 | $html_addr_search_done = 'Use Addresses'; |
953fa718 |
97 | } |
98 | |
99 | /** GET VARS */ |
100 | sqgetGlobalVar('attachedmessages', $attachedmessages, SQ_GET); |
8780308f |
101 | if ( sqgetGlobalVar('account', $temp, SQ_GET) ) { |
102 | $iAccount = (int) $temp; |
103 | } else { |
104 | $iAccount = 0; |
105 | } |
106 | |
0b97a708 |
107 | |
98a9cc03 |
108 | /** get smaction */ |
109 | if ( !sqgetGlobalVar('smaction',$action) ) |
110 | { |
73ad81bf |
111 | if ( sqgetGlobalVar('smaction_reply',$tmp) ) $action = 'reply'; |
112 | if ( sqgetGlobalVar('smaction_reply_all',$tmp) ) $action = 'reply_all'; |
113 | if ( sqgetGlobalVar('smaction_forward',$tmp) ) $action = 'forward'; |
114 | if ( sqgetGlobalVar('smaction_attache',$tmp) ) $action = 'forward_as_attachment'; |
115 | if ( sqgetGlobalVar('smaction_draft',$tmp) ) $action = 'draft'; |
116 | if ( sqgetGlobalVar('smaction_edit_new',$tmp) ) $action = 'edit_as_new'; |
98a9cc03 |
117 | } |
118 | |
3461167c |
119 | /* Location (For HTTP 1.1 Header("Location: ...") redirects) */ |
120 | $location = get_location(); |
1e2a6ff6 |
121 | /* Identities (fetch only once) */ |
122 | $idents = get_identities(); |
3461167c |
123 | |
09044055 |
124 | /* --------------------- Specific Functions ------------------------------ */ |
0b97a708 |
125 | |
41b94d65 |
126 | function replyAllString($header) { |
73ad81bf |
127 | global $include_self_reply_all, $idents; |
128 | $excl_ar = array(); |
129 | /** |
130 | * 1) Remove the addresses we'll be sending the message 'to' |
131 | */ |
73ad81bf |
132 | if (isset($header->replyto)) { |
133 | $excl_ar = $header->getAddr_a('replyto'); |
134 | } |
135 | /** |
136 | * 2) Remove our identities from the CC list (they still can be in the |
137 | * TO list) only if $include_self_reply_all is turned off |
138 | */ |
139 | if (!$include_self_reply_all) { |
140 | foreach($idents as $id) { |
141 | $excl_ar[strtolower(trim($id['email_address']))] = ''; |
142 | } |
143 | } |
144 | |
145 | /** |
146 | * 3) get the addresses. |
147 | */ |
148 | $url_replytoall_ar = $header->getAddr_a(array('to','cc'), $excl_ar); |
149 | |
150 | /** |
151 | * 4) generate the string. |
152 | */ |
153 | $url_replytoallcc = ''; |
154 | foreach( $url_replytoall_ar as $email => $personal) { |
155 | if ($personal) { |
156 | // if personal name contains address separator then surround |
157 | // the personal name with double quotes. |
158 | if (strpos($personal,',') !== false) { |
159 | $personal = '"'.$personal.'"'; |
160 | } |
161 | $url_replytoallcc .= ", $personal <$email>"; |
162 | } else { |
163 | $url_replytoallcc .= ', '. $email; |
1e2a6ff6 |
164 | } |
73ad81bf |
165 | } |
166 | $url_replytoallcc = substr($url_replytoallcc,2); |
167 | |
168 | return $url_replytoallcc; |
09044055 |
169 | } |
170 | |
50706f77 |
171 | /** |
172 | * creates top line in reply citations |
173 | * |
174 | * Line style depends on user preferences. |
175 | * $orig_date argument is available only from 1.4.3 and 1.5.1 version. |
176 | * @param object $orig_from From: header object. |
177 | * @param integer $orig_date email's timestamp |
178 | * @return string reply citation |
179 | */ |
b0323712 |
180 | function getReplyCitation($orig_from, $orig_date) { |
12a0ed01 |
181 | global $reply_citation_style, $reply_citation_start, $reply_citation_end; |
50706f77 |
182 | |
05f7db7a |
183 | if (!is_object($orig_from)) { |
d1205176 |
184 | $sOrig_from = ''; |
05f7db7a |
185 | } else { |
d1205176 |
186 | $sOrig_from = decodeHeader($orig_from->getAddress(false),false,false,true); |
05f7db7a |
187 | } |
91c27aee |
188 | |
12a0ed01 |
189 | /* First, return an empty string when no citation style selected. */ |
190 | if (($reply_citation_style == '') || ($reply_citation_style == 'none')) { |
191 | return ''; |
192 | } |
193 | |
194 | /* Make sure our final value isn't an empty string. */ |
d1205176 |
195 | if ($sOrig_from == '') { |
12a0ed01 |
196 | return ''; |
197 | } |
198 | |
199 | /* Otherwise, try to select the desired citation style. */ |
200 | switch ($reply_citation_style) { |
50706f77 |
201 | case 'author_said': |
202 | /** |
203 | * To translators: %s is for author's name |
204 | */ |
d1205176 |
205 | $full_reply_citation = sprintf(_("%s wrote:"),$sOrig_from); |
50706f77 |
206 | break; |
207 | case 'quote_who': |
a42c236f |
208 | $start = '<quote who="'; |
50706f77 |
209 | $end = '">'; |
d1205176 |
210 | $full_reply_citation = $start . $sOrig_from . $end; |
50706f77 |
211 | break; |
212 | case 'date_time_author': |
213 | /** |
214 | * To translators: |
91c27aee |
215 | * first %s is for date string, second %s is for author's name. Date uses |
50706f77 |
216 | * formating from "D, F j, Y g:i a" and "D, F j, Y H:i" translations. |
217 | * Example string: |
0e1a248b |
218 | * "On Sat, December 24, 2004 23:59, Santa wrote:" |
50706f77 |
219 | * If you have to put author's name in front of date string, check comments about |
220 | * argument swapping at http://www.php.net/sprintf |
221 | */ |
d1205176 |
222 | $full_reply_citation = sprintf(_("On %s, %s wrote:"), getLongDateString($orig_date), $sOrig_from); |
50706f77 |
223 | break; |
224 | case 'user-defined': |
225 | $start = $reply_citation_start . |
226 | ($reply_citation_start == '' ? '' : ' '); |
227 | $end = $reply_citation_end; |
d1205176 |
228 | $full_reply_citation = $start . $sOrig_from . $end; |
50706f77 |
229 | break; |
230 | default: |
231 | return ''; |
232 | } |
233 | |
234 | /* Add line feed and return the citation string. */ |
235 | return ($full_reply_citation . "\n"); |
12a0ed01 |
236 | } |
237 | |
50706f77 |
238 | /** |
239 | * Creates header fields in forwarded email body |
240 | * |
91c27aee |
241 | * $default_charset global must be set correctly before you call this function. |
50706f77 |
242 | * @param object $orig_header |
91c27aee |
243 | * @return $string |
50706f77 |
244 | */ |
41b94d65 |
245 | function getforwardHeader($orig_header) { |
50706f77 |
246 | global $editor_size, $default_charset; |
247 | |
248 | // using own strlen function in order to detect correct string length |
249 | $display = array( _("Subject") => sq_strlen(_("Subject"),$default_charset), |
250 | _("From") => sq_strlen(_("From"),$default_charset), |
251 | _("Date") => sq_strlen(_("Date"),$default_charset), |
252 | _("To") => sq_strlen(_("To"),$default_charset), |
253 | _("Cc") => sq_strlen(_("Cc"),$default_charset) ); |
73ad81bf |
254 | $maxsize = max($display); |
255 | $indent = str_pad('',$maxsize+2); |
256 | foreach($display as $key => $val) { |
257 | $display[$key] = $key .': '. str_pad('', $maxsize - $val); |
258 | } |
259 | $from = decodeHeader($orig_header->getAddr_s('from',"\n$indent"),false,false,true); |
260 | $from = str_replace(' ',' ',$from); |
261 | $to = decodeHeader($orig_header->getAddr_s('to',"\n$indent"),false,false,true); |
262 | $to = str_replace(' ',' ',$to); |
263 | $subject = decodeHeader($orig_header->subject,false,false,true); |
264 | $subject = str_replace(' ',' ',$subject); |
50706f77 |
265 | |
266 | // using own str_pad function in order to create correct string pad |
267 | $bodyTop = sq_str_pad(' '._("Original Message").' ',$editor_size -2,'-',STR_PAD_BOTH,$default_charset) . |
73ad81bf |
268 | "\n". $display[_("Subject")] . $subject . "\n" . |
269 | $display[_("From")] . $from . "\n" . |
270 | $display[_("Date")] . getLongDateString( $orig_header->date ). "\n" . |
271 | $display[_("To")] . $to . "\n"; |
272 | if ($orig_header->cc != array() && $orig_header->cc !='') { |
273 | $cc = decodeHeader($orig_header->getAddr_s('cc',"\n$indent"),false,false,true); |
274 | $cc = str_replace(' ',' ',$cc); |
275 | $bodyTop .= $display[_("Cc")] .$cc . "\n"; |
276 | } |
277 | $bodyTop .= str_pad('', $editor_size -2 , '-') . |
278 | "\n\n"; |
279 | return $bodyTop; |
41b94d65 |
280 | } |
09044055 |
281 | /* ----------------------------------------------------------------------- */ |
282 | |
44560457 |
283 | /* |
1c044820 |
284 | * If the session is expired during a post this restores the compose session |
44560457 |
285 | * vars. |
286 | */ |
5da08ef7 |
287 | if (sqsession_is_registered('session_expired_post')) { |
953fa718 |
288 | sqgetGlobalVar('session_expired_post', $session_expired_post, SQ_SESSION); |
1c044820 |
289 | /* |
40934000 |
290 | * extra check for username so we don't display previous post data from |
291 | * another user during this session. |
292 | */ |
293 | if ($session_expired_post['username'] != $username) { |
0ec1a14b |
294 | unset($session_expired_post); |
0b97a708 |
295 | sqsession_unregister('session_expired_post'); |
0ec1a14b |
296 | session_write_close(); |
40934000 |
297 | } else { |
c6f28eb1 |
298 | // these are the vars that we can set from the expired composed session |
299 | $compo_var_list = array ( 'send_to', 'send_to_cc','body','startMessage', |
300 | 'passed_body','use_signature','signature','attachments','subject','newmail', |
301 | 'send_to_bcc', 'passed_id', 'mailbox', 'from_htmladdr_search', 'identity', |
302 | 'draft_id', 'delete_draft', 'mailprio', 'edit_as_new', 'compose_messsages', |
303 | 'composesession', 'request_mdn', 'request_dr'); |
304 | |
305 | foreach ($compo_var_list as $var) { |
306 | if ( isset($session_expired_post[$var]) && !isset($$var) ) { |
307 | $$var = $session_expired_post[$var]; |
40934000 |
308 | } |
c6f28eb1 |
309 | |
0ec1a14b |
310 | $compose_messages = unserialize(urldecode($restoremessages)); |
311 | sqsession_register($compose_messages,'compose_messages'); |
312 | sqsession_register($composesession,'composesession'); |
40934000 |
313 | if (isset($send)) { |
314 | unset($send); |
315 | } |
316 | $session_expired = true; |
317 | } |
5da08ef7 |
318 | unset($session_expired_post); |
0b97a708 |
319 | sqsession_unregister('session_expired_post'); |
5da08ef7 |
320 | session_write_close(); |
40934000 |
321 | if (!isset($mailbox)) { |
322 | $mailbox = ''; |
323 | } |
324 | if ($compose_new_win == '1') { |
325 | compose_Header($color, $mailbox); |
326 | } else { |
91c27aee |
327 | $sHeaderJs = (isset($sHeaderJs)) ? $sHeaderJs : ''; |
328 | if (strpos($action, 'reply') !== false && $reply_focus) { |
329 | $sBodyTagJs = 'onload="checkForm(\''.$replyfocus.'\');"'; |
330 | } else { |
331 | $sBodyTagJs = 'onload="checkForm();"'; |
332 | } |
333 | displayPageHeader($color, $mailbox,$sHeaderJs,$sBodyTagJs); |
40934000 |
334 | } |
335 | showInputForm($session, false); |
336 | exit(); |
44560457 |
337 | } |
da95c4b6 |
338 | if (!isset($composesession)) { |
339 | $composesession = 0; |
a43e4b90 |
340 | sqsession_register(0,'composesession'); |
da95c4b6 |
341 | } |
342 | |
d7f8e6e6 |
343 | if (!isset($session) || (isset($newmessage) && $newmessage)) { |
0b97a708 |
344 | sqsession_unregister('composesession'); |
1c044820 |
345 | $session = "$composesession" +1; |
91f2085b |
346 | $composesession = $session; |
a43e4b90 |
347 | sqsession_register($composesession,'composesession'); |
1c044820 |
348 | } |
a43e4b90 |
349 | if (!isset($compose_messages)) { |
73ad81bf |
350 | $compose_messages = array(); |
a43e4b90 |
351 | } |
91c27aee |
352 | |
40934000 |
353 | if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)) { |
73ad81bf |
354 | $composeMessage = new Message(); |
355 | $rfc822_header = new Rfc822Header(); |
356 | $composeMessage->rfc822_header = $rfc822_header; |
357 | $composeMessage->reply_rfc822_header = ''; |
358 | $compose_messages[$session] = $composeMessage; |
91c27aee |
359 | |
73ad81bf |
360 | sqsession_register($compose_messages,'compose_messages'); |
5628fdde |
361 | } else { |
73ad81bf |
362 | $composeMessage=$compose_messages[$session]; |
a43e4b90 |
363 | } |
a43e4b90 |
364 | |
00793a25 |
365 | if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None')) { |
366 | $mailbox = 'INBOX'; |
367 | } |
368 | |
4dfb9db7 |
369 | if ($draft) { |
370 | /* |
371 | * Set $default_charset to correspond with the user's selection |
372 | * of language interface. |
373 | */ |
374 | set_my_charset(); |
375 | $composeMessage=$compose_messages[$session]; |
b7ff469f |
376 | if (! deliverMessage($composeMessage, true)) { |
da95c4b6 |
377 | showInputForm($session); |
00793a25 |
378 | exit(); |
734f4ee6 |
379 | } else { |
5da08ef7 |
380 | unset($compose_messages[$session]); |
00793a25 |
381 | $draft_message = _("Draft Email Saved"); |
382 | /* If this is a resumed draft, then delete the original */ |
383 | if(isset($delete_draft)) { |
b034bca2 |
384 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, false); |
385 | sqimap_mailbox_select($imap_stream, $draft_folder); |
386 | // force bypass_trash=true because message should be saved when deliverMessage() returns true. |
91c27aee |
387 | // in current implementation of sqimap_msgs_list_flag() single message id can |
b034bca2 |
388 | // be submitted as string. docs state that it should be array. |
389 | sqimap_msgs_list_delete($imap_stream, $draft_folder, $delete_draft, true); |
390 | if ($auto_expunge) { |
391 | sqimap_mailbox_expunge($imap_stream, $draft_folder, true); |
9c3e6cd4 |
392 | } |
b034bca2 |
393 | sqimap_logout($imap_stream); |
394 | } |
81de00c0 |
395 | if (count($oErrorHandler->aErrors)) { |
396 | sqsession_register($oErrorHandler->aErrors,"delayed_errors"); |
397 | } |
c077ffeb |
398 | session_write_close(); |
b034bca2 |
399 | if ($compose_new_win == '1') { |
09047d19 |
400 | if ( !isset($pageheader_sent) || !$pageheader_sent ) { |
401 | Header("Location: $location/compose.php?saved_draft=yes&session=$composesession"); |
402 | } else { |
f265009a |
403 | echo ' <br><br><div style="text-align: center;"><a href="' . $location |
09047d19 |
404 | . '/compose.php?saved_sent=yes&session=' . $composesession . '">' |
f265009a |
405 | . _("Return") . '</a></div>'; |
a6d3eff6 |
406 | } |
b034bca2 |
407 | exit(); |
408 | } else { |
09047d19 |
409 | if ( !isset($pageheader_sent) || !$pageheader_sent ) { |
410 | Header("Location: $location/right_main.php?mailbox=" . urlencode($draft_folder) . |
b034bca2 |
411 | "&startMessage=1¬e=".urlencode($draft_message)); |
09047d19 |
412 | } else { |
f265009a |
413 | echo ' <br><br><div style="text-align: center;"><a href="' . $location |
09047d19 |
414 | . '/right_main.php?mailbox=' . urlencode($draft_folder) |
415 | . '&startMessage=1&note=' . urlencode($draft_message) .'">' |
f265009a |
416 | . _("Return") . '</a></div>'; |
a6d3eff6 |
417 | } |
b034bca2 |
418 | exit(); |
00793a25 |
419 | } |
420 | } |
421 | } |
422 | |
4dfb9db7 |
423 | if ($send) { |
0b97a708 |
424 | if (isset($_FILES['attachfile']) && |
73ad81bf |
425 | $_FILES['attachfile']['tmp_name'] && |
426 | $_FILES['attachfile']['tmp_name'] != 'none') { |
da95c4b6 |
427 | $AttachFailure = saveAttachedFiles($session); |
00793a25 |
428 | } |
429 | if (checkInput(false) && !isset($AttachFailure)) { |
73ad81bf |
430 | if ($mailbox == "All Folders") { |
431 | /* We entered compose via the search results page */ |
a42c236f |
432 | $mailbox = 'INBOX'; /* Send 'em to INBOX, that's safe enough */ |
73ad81bf |
433 | } |
00793a25 |
434 | $urlMailbox = urlencode (trim($mailbox)); |
3f6b1b6f |
435 | if (! isset($passed_id)) { |
436 | $passed_id = 0; |
00793a25 |
437 | } |
d4c5c50c |
438 | /** |
00793a25 |
439 | * Set $default_charset to correspond with the user's selection |
7058a2a9 |
440 | * of language interface. |
00793a25 |
441 | */ |
442 | set_my_charset(); |
d4c5c50c |
443 | /** |
00793a25 |
444 | * This is to change all newlines to \n |
7058a2a9 |
445 | * We'll change them to \r\n later (in the sendMessage function) |
00793a25 |
446 | */ |
447 | $body = str_replace("\r\n", "\n", $body); |
448 | $body = str_replace("\r", "\n", $body); |
449 | |
d4c5c50c |
450 | /** |
18c9998a |
451 | * Rewrap $body so that no line is bigger than $editor_size |
00793a25 |
452 | */ |
18c9998a |
453 | $body = explode("\n", $body); |
454 | $newBody = ''; |
455 | foreach ($body as $line) { |
456 | if( $line <> '-- ' ) { |
73ad81bf |
457 | $line = rtrim($line); |
18c9998a |
458 | } |
200c9b8e |
459 | if (sq_strlen($line,$default_charset) <= $editor_size + 1) { |
18c9998a |
460 | $newBody .= $line . "\n"; |
461 | } else { |
200c9b8e |
462 | sqWordWrap($line, $editor_size,$default_charset); |
18c9998a |
463 | $newBody .= $line . "\n"; |
464 | |
465 | } |
466 | |
467 | } |
468 | $body = $newBody; |
1c044820 |
469 | |
a43e4b90 |
470 | $composeMessage=$compose_messages[$session]; |
d5181a1d |
471 | |
a91189d6 |
472 | $Result = deliverMessage($composeMessage); |
81de00c0 |
473 | |
19c4e72d |
474 | do_hook('compose_send_after', $Result, $composeMessage); |
00793a25 |
475 | if (! $Result) { |
da95c4b6 |
476 | showInputForm($session); |
00793a25 |
477 | exit(); |
478 | } |
dd4a44cd |
479 | unset($compose_messages[$session]); |
5c4ff7bf |
480 | |
b034bca2 |
481 | /* if it is resumed draft, delete draft message */ |
00793a25 |
482 | if ( isset($delete_draft)) { |
b034bca2 |
483 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, false); |
484 | sqimap_mailbox_select($imap_stream, $draft_folder); |
485 | // bypass_trash=true because message should be saved when deliverMessage() returns true. |
91c27aee |
486 | // in current implementation of sqimap_msgs_list_flag() single message id can |
b034bca2 |
487 | // be submitted as string. docs state that it should be array. |
488 | sqimap_msgs_list_delete($imap_stream, $draft_folder, $delete_draft, true); |
489 | if ($auto_expunge) { |
490 | sqimap_mailbox_expunge($imap_stream, $draft_folder, true); |
491 | } |
492 | sqimap_logout($imap_stream); |
00793a25 |
493 | } |
81de00c0 |
494 | /* |
495 | * Store the error array in the session because they will be lost on a redirect |
496 | */ |
497 | if (count($oErrorHandler->aErrors)) { |
498 | sqsession_register($oErrorHandler->aErrors,"delayed_errors"); |
499 | } |
c077ffeb |
500 | session_write_close(); |
9c3e6cd4 |
501 | if ($compose_new_win == '1') { |
09047d19 |
502 | if ( !isset($pageheader_sent) || !$pageheader_sent ) { |
503 | Header("Location: $location/compose.php?mail_sent=yes"); |
504 | } else { |
f265009a |
505 | echo ' <br><br><div style="text-align: center;"><a href="' . $location |
09047d19 |
506 | . '/compose.php?mail_sent=yes">' |
f265009a |
507 | . _("Return") . '</a></div>'; |
09047d19 |
508 | } |
509 | exit(); |
510 | } else { |
511 | if ( !isset($pageheader_sent) || !$pageheader_sent ) { |
512 | Header("Location: $location/right_main.php?mailbox=$urlMailbox". |
513 | "&startMessage=$startMessage&mail_sent=yes"); |
514 | } else { |
f265009a |
515 | echo ' <br><br><div style="text-align: center;"><a href="' . $location |
09047d19 |
516 | . "/right_main.php?mailbox=$urlMailbox" |
517 | . "&startMessage=$startMessage&mail_sent=yes\">" |
f265009a |
518 | . _("Return") . '</a></div>'; |
09047d19 |
519 | } |
520 | exit(); |
9c3e6cd4 |
521 | } |
734f4ee6 |
522 | } else { |
9c3e6cd4 |
523 | if ($compose_new_win == '1') { |
524 | compose_Header($color, $mailbox); |
525 | } |
526 | else { |
527 | displayPageHeader($color, $mailbox); |
528 | } |
00793a25 |
529 | if (isset($AttachFailure)) { |
73ad81bf |
530 | plain_error_message(_("Could not move/copy file. File not attached"), |
531 | $color); |
00793a25 |
532 | } |
00793a25 |
533 | checkInput(true); |
da95c4b6 |
534 | showInputForm($session); |
00793a25 |
535 | /* sqimap_logout($imapConnection); */ |
536 | } |
e02775fe |
537 | } elseif (isset($html_addr_search_done)) { |
73ad81bf |
538 | if ($compose_new_win == '1') { |
539 | compose_Header($color, $mailbox); |
540 | } |
541 | else { |
542 | displayPageHeader($color, $mailbox); |
543 | } |
00793a25 |
544 | |
545 | if (isset($send_to_search) && is_array($send_to_search)) { |
546 | foreach ($send_to_search as $k => $v) { |
547 | if (substr($k, 0, 1) == 'T') { |
548 | if ($send_to) { |
549 | $send_to .= ', '; |
550 | } |
551 | $send_to .= $v; |
552 | } |
553 | elseif (substr($k, 0, 1) == 'C') { |
554 | if ($send_to_cc) { |
555 | $send_to_cc .= ', '; |
556 | } |
557 | $send_to_cc .= $v; |
558 | } |
559 | elseif (substr($k, 0, 1) == 'B') { |
560 | if ($send_to_bcc) { |
561 | $send_to_bcc .= ', '; |
562 | } |
563 | $send_to_bcc .= $v; |
564 | } |
565 | } |
566 | } |
da95c4b6 |
567 | showInputForm($session); |
e02775fe |
568 | } elseif (isset($html_addr_search)) { |
0b97a708 |
569 | if (isset($_FILES['attachfile']) && |
73ad81bf |
570 | $_FILES['attachfile']['tmp_name'] && |
571 | $_FILES['attachfile']['tmp_name'] != 'none') { |
0b97a708 |
572 | if(saveAttachedFiles($session)) { |
cb34dbd0 |
573 | plain_error_message(_("Could not move/copy file. File not attached")); |
00793a25 |
574 | } |
575 | } |
576 | /* |
577 | * I am using an include so as to elminiate an extra unnecessary |
578 | * click. If you can think of a better way, please implement it. |
579 | */ |
580 | include_once('./addrbook_search_html.php'); |
e02775fe |
581 | } elseif (isset($attach)) { |
73ad81bf |
582 | if ($compose_new_win == '1') { |
583 | compose_Header($color, $mailbox); |
584 | } else { |
585 | displayPageHeader($color, $mailbox); |
586 | } |
5a3e52f3 |
587 | if (saveAttachedFiles($session)) { |
cb34dbd0 |
588 | plain_error_message(_("Could not move/copy file. File not attached")); |
5a3e52f3 |
589 | } |
da95c4b6 |
590 | showInputForm($session); |
01265fba |
591 | } |
592 | elseif (isset($sigappend)) { |
1e2a6ff6 |
593 | $signature = $idents[$identity]['signature']; |
594 | |
01265fba |
595 | $body .= "\n\n".($prefix_sig==true? "-- \n":'').$signature; |
596 | if ($compose_new_win == '1') { |
73ad81bf |
597 | compose_Header($color, $mailbox); |
01265fba |
598 | } else { |
599 | displayPageHeader($color, $mailbox); |
600 | } |
da95c4b6 |
601 | showInputForm($session); |
e02775fe |
602 | } elseif (isset($do_delete)) { |
73ad81bf |
603 | if ($compose_new_win == '1') { |
604 | compose_Header($color, $mailbox); |
605 | } else { |
606 | displayPageHeader($color, $mailbox); |
607 | } |
00793a25 |
608 | |
00793a25 |
609 | if (isset($delete) && is_array($delete)) { |
a43e4b90 |
610 | $composeMessage = $compose_messages[$session]; |
00793a25 |
611 | foreach($delete as $index) { |
a58b05b4 |
612 | if (!empty($composeMessage->entities) && isset($composeMessage->entities[$index])) { |
c077ffeb |
613 | $composeMessage->entities[$index]->purgeAttachments(); |
a58b05b4 |
614 | unset ($composeMessage->entities[$index]); |
615 | } |
a91189d6 |
616 | } |
617 | $new_entities = array(); |
618 | foreach ($composeMessage->entities as $entity) { |
619 | $new_entities[] = $entity; |
00793a25 |
620 | } |
a91189d6 |
621 | $composeMessage->entities = $new_entities; |
622 | $compose_messages[$session] = $composeMessage; |
623 | sqsession_register($compose_messages, 'compose_messages'); |
00793a25 |
624 | } |
da95c4b6 |
625 | showInputForm($session); |
734f4ee6 |
626 | } else { |
00793a25 |
627 | /* |
628 | * This handles the default case as well as the error case |
1c044820 |
629 | * (they had the same code) --> if (isset($smtpErrors)) |
00793a25 |
630 | */ |
44560457 |
631 | |
632 | if ($compose_new_win == '1') { |
73ad81bf |
633 | compose_Header($color, $mailbox); |
44560457 |
634 | } else { |
73ad81bf |
635 | displayPageHeader($color, $mailbox); |
44560457 |
636 | } |
00793a25 |
637 | |
638 | $newmail = true; |
639 | |
a61878d0 |
640 | if (!isset($passed_ent_id)) { |
641 | $passed_ent_id = ''; |
642 | } |
643 | if (!isset($passed_id)) { |
1c044820 |
644 | $passed_id = ''; |
a61878d0 |
645 | } |
646 | if (!isset($mailbox)) { |
647 | $mailbox = ''; |
1c044820 |
648 | } |
a61878d0 |
649 | if (!isset($action)) { |
650 | $action = ''; |
651 | } |
1c044820 |
652 | |
44560457 |
653 | $values = newMail($mailbox,$passed_id,$passed_ent_id, $action, $session); |
b9928adc |
654 | |
655 | /* in case the origin is not read_body.php */ |
656 | if (isset($send_to)) { |
73ad81bf |
657 | $values['send_to'] = $send_to; |
b9928adc |
658 | } |
659 | if (isset($send_to_cc)) { |
73ad81bf |
660 | $values['send_to_cc'] = $send_to_cc; |
b9928adc |
661 | } |
662 | if (isset($send_to_bcc)) { |
73ad81bf |
663 | $values['send_to_bcc'] = $send_to_bcc; |
b9928adc |
664 | } |
2a2f2185 |
665 | if (isset($subject)) { |
73ad81bf |
666 | $values['subject'] = $subject; |
2a2f2185 |
667 | } |
41b94d65 |
668 | showInputForm($session, $values); |
00793a25 |
669 | } |
670 | |
671 | exit(); |
672 | |
00793a25 |
673 | /**************** Only function definitions go below *************/ |
674 | |
92c6f757 |
675 | function getforwardSubject($subject) |
676 | { |
677 | if ((substr(strtolower($subject), 0, 4) != 'fwd:') && |
73ad81bf |
678 | (substr(strtolower($subject), 0, 5) != '[fwd:') && |
679 | (substr(strtolower($subject), 0, 6) != '[ fwd:')) { |
92c6f757 |
680 | $subject = '[Fwd: ' . $subject . ']'; |
681 | } |
682 | return $subject; |
683 | } |
00793a25 |
684 | |
48985d59 |
685 | /* This function is used when not sending or adding attachments */ |
44560457 |
686 | function newMail ($mailbox='', $passed_id='', $passed_ent_id='', $action='', $session='') { |
1e2a6ff6 |
687 | global $editor_size, $default_use_priority, $body, $idents, |
ce68b76b |
688 | $use_signature, $data_dir, $username, |
c6f28eb1 |
689 | $key, $imapServerAddress, $imapPort, $compose_messages, |
73ad81bf |
690 | $composeMessage, $body_quote; |
4e519821 |
691 | global $languages, $squirrelmail_language, $default_charset; |
e7f1a81d |
692 | |
d4f20027 |
693 | /* |
694 | * Set $default_charset to correspond with the user's selection |
695 | * of language interface. $default_charset global is not correct, |
696 | * if message is composed in new window. |
697 | */ |
698 | set_my_charset(); |
699 | |
91f2085b |
700 | $send_to = $send_to_cc = $send_to_bcc = $subject = $identity = ''; |
bdb92db3 |
701 | $mailprio = 3; |
44560457 |
702 | |
41b94d65 |
703 | if ($passed_id) { |
44560457 |
704 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, |
73ad81bf |
705 | $imapPort, 0); |
a61878d0 |
706 | |
48985d59 |
707 | sqimap_mailbox_select($imapConnection, $mailbox); |
41b94d65 |
708 | $message = sqimap_get_message($imapConnection, $passed_id, $mailbox); |
1c044820 |
709 | |
a61878d0 |
710 | $body = ''; |
711 | if ($passed_ent_id) { |
712 | /* redefine the messsage in case of message/rfc822 */ |
713 | $message = $message->getEntity($passed_ent_id); |
714 | /* message is an entity which contains the envelope and type0=message |
73ad81bf |
715 | * and type1=rfc822. The actual entities are childs from |
716 | * $message->entities[0]. That's where the encoding and is located |
717 | */ |
a61878d0 |
718 | |
719 | $entities = $message->entities[0]->findDisplayEntity |
73ad81bf |
720 | (array(), $alt_order = array('text/plain')); |
a61878d0 |
721 | if (!count($entities)) { |
722 | $entities = $message->entities[0]->findDisplayEntity |
73ad81bf |
723 | (array(), $alt_order = array('text/plain','html/plain')); |
a61878d0 |
724 | } |
725 | $orig_header = $message->rfc822_header; /* here is the envelope located */ |
726 | /* redefine the message for picking up the attachments */ |
727 | $message = $message->entities[0]; |
728 | |
729 | } else { |
730 | $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain')); |
731 | if (!count($entities)) { |
732 | $entities = $message->findDisplayEntity (array(), $alt_order = array('text/plain','html/plain')); |
733 | } |
734 | $orig_header = $message->rfc822_header; |
735 | } |
1c044820 |
736 | |
a61878d0 |
737 | $type0 = $message->type0; |
738 | $type1 = $message->type1; |
41b94d65 |
739 | foreach ($entities as $ent) { |
b455e47b |
740 | $msg = $message->getEntity($ent); |
741 | $type0 = $msg->type0; |
742 | $type1 = $msg->type1; |
a61878d0 |
743 | $unencoded_bodypart = mime_fetch_body($imapConnection, $passed_id, $ent); |
744 | $body_part_entity = $message->getEntity($ent); |
745 | $bodypart = decodeBody($unencoded_bodypart, |
73ad81bf |
746 | $body_part_entity->header->encoding); |
a61878d0 |
747 | if ($type1 == 'html') { |
5b755d9f |
748 | $bodypart = str_replace("\n", ' ', $bodypart); |
bb977394 |
749 | $bodypart = preg_replace(array('/<\/?p>/i','/<div><\/div>/i','/<br\s*(\/)*>/i','/<\/?div>/i'), "\n", $bodypart); |
5b755d9f |
750 | $bodypart = str_replace(array(' ','>','<'),array(' ','>','<'),$bodypart); |
a61878d0 |
751 | $bodypart = strip_tags($bodypart); |
752 | } |
e842b215 |
753 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
73ad81bf |
754 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode')) { |
e842b215 |
755 | if (mb_detect_encoding($bodypart) != 'ASCII') { |
f4bb5d22 |
756 | $bodypart = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_decode', $bodypart); |
e842b215 |
757 | } |
758 | } |
eceefdfe |
759 | |
bfa54da7 |
760 | // charset encoding in compose form stuff |
73ad81bf |
761 | if (isset($body_part_entity->header->parameters['charset'])) { |
762 | $actual = $body_part_entity->header->parameters['charset']; |
763 | } else { |
764 | $actual = 'us-ascii'; |
765 | } |
beca818e |
766 | |
73ad81bf |
767 | if ( $actual && is_conversion_safe($actual) && $actual != $default_charset){ |
768 | $bodypart = charset_convert($actual,$bodypart,$default_charset,false); |
769 | } |
bfa54da7 |
770 | // end of charset encoding in compose |
eceefdfe |
771 | |
a61878d0 |
772 | $body .= $bodypart; |
773 | } |
774 | if ($default_use_priority) { |
775 | $mailprio = substr($orig_header->priority,0,1); |
776 | if (!$mailprio) { |
777 | $mailprio = 3; |
778 | } |
779 | } else { |
780 | $mailprio = ''; |
781 | } |
bdb92db3 |
782 | |
783 | $identity = ''; |
a45887d7 |
784 | $from_o = $orig_header->from; |
fe868193 |
785 | if (is_array($from_o)) { |
786 | if (isset($from_o[0])) { |
787 | $from_o = $from_o[0]; |
788 | } |
789 | } |
bdb92db3 |
790 | if (is_object($from_o)) { |
791 | $orig_from = $from_o->getAddress(); |
792 | } else { |
793 | $orig_from = ''; |
a61878d0 |
794 | } |
1e2a6ff6 |
795 | |
a91189d6 |
796 | $identities = array(); |
1e2a6ff6 |
797 | if (count($idents) > 1) { |
798 | foreach($idents as $nr=>$data) { |
799 | $enc_from_name = '"'.$data['full_name'].'" <'. $data['email_address'].'>'; |
800 | if($enc_from_name == $orig_from) { |
801 | $identity = $nr; |
a61878d0 |
802 | break; |
803 | } |
a91189d6 |
804 | $identities[] = $enc_from_name; |
805 | } |
1e2a6ff6 |
806 | |
a91189d6 |
807 | $identity_match = $orig_header->findAddress($identities); |
808 | if ($identity_match) { |
809 | $identity = $identity_match; |
a61878d0 |
810 | } |
bdb92db3 |
811 | } |
a61878d0 |
812 | |
813 | switch ($action) { |
73ad81bf |
814 | case ('draft'): |
815 | $use_signature = FALSE; |
816 | $composeMessage->rfc822_header = $orig_header; |
817 | $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true); |
818 | $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true); |
819 | $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true); |
820 | $send_from = $orig_header->getAddr_s('from'); |
821 | $send_from_parts = new AddressStructure(); |
822 | $send_from_parts = $orig_header->parseAddress($send_from); |
823 | $send_from_add = $send_from_parts->mailbox . '@' . $send_from_parts->host; |
824 | $identities = get_identities(); |
825 | if (count($identities) > 0) { |
826 | foreach($identities as $iddata) { |
827 | if ($send_from_add == $iddata['email_address']) { |
828 | $identity = $iddata['index']; |
829 | break; |
830 | } |
a656569f |
831 | } |
832 | } |
73ad81bf |
833 | $subject = decodeHeader($orig_header->subject,false,false,true); |
834 | /* remember the references and in-reply-to headers in case of an reply */ |
835 | $composeMessage->rfc822_header->more_headers['References'] = $orig_header->references; |
836 | $composeMessage->rfc822_header->more_headers['In-Reply-To'] = $orig_header->in_reply_to; |
837 | // rewrap the body to clean up quotations and line lengths |
838 | sqBodyWrap($body, $editor_size); |
839 | $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); |
840 | break; |
841 | case ('edit_as_new'): |
842 | $send_to = decodeHeader($orig_header->getAddr_s('to'),false,false,true); |
843 | $send_to_cc = decodeHeader($orig_header->getAddr_s('cc'),false,false,true); |
844 | $send_to_bcc = decodeHeader($orig_header->getAddr_s('bcc'),false,false,true); |
845 | $subject = decodeHeader($orig_header->subject,false,false,true); |
846 | $mailprio = $orig_header->priority; |
847 | $orig_from = ''; |
848 | $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); |
849 | // rewrap the body to clean up quotations and line lengths |
850 | sqBodyWrap($body, $editor_size); |
851 | break; |
852 | case ('forward'): |
853 | $send_to = ''; |
854 | $subject = getforwardSubject(decodeHeader($orig_header->subject,false,false,true)); |
855 | $body = getforwardHeader($orig_header) . $body; |
856 | // the logic for calling sqUnWordWrap here would be to allow the browser to wrap the lines |
857 | // forwarded message text should be as undisturbed as possible, so commenting out this call |
858 | // sqUnWordWrap($body); |
859 | $composeMessage = getAttachments($message, $composeMessage, $passed_id, $entities, $imapConnection); |
91c27aee |
860 | |
73ad81bf |
861 | //add a blank line after the forward headers |
862 | $body = "\n" . $body; |
863 | break; |
864 | case ('forward_as_attachment'): |
865 | $subject = getforwardSubject(decodeHeader($orig_header->subject,false,false,true)); |
866 | $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, $passed_ent_id, $imapConnection); |
867 | $body = ''; |
868 | break; |
869 | case ('reply_all'): |
870 | if(isset($orig_header->mail_followup_to) && $orig_header->mail_followup_to) { |
871 | $send_to = $orig_header->getAddr_s('mail_followup_to'); |
b268e66b |
872 | } else { |
73ad81bf |
873 | $send_to_cc = replyAllString($orig_header); |
874 | $send_to_cc = decodeHeader($send_to_cc,false,false,true); |
b268e66b |
875 | } |
73ad81bf |
876 | case ('reply'): |
877 | // skip this if send_to was already set right above here |
878 | if(!$send_to) { |
879 | $send_to = $orig_header->reply_to; |
880 | if (is_array($send_to) && count($send_to)) { |
881 | $send_to = $orig_header->getAddr_s('reply_to'); |
882 | } else if (is_object($send_to)) { /* unneccesarry, just for failsafe purpose */ |
883 | $send_to = $orig_header->getAddr_s('reply_to'); |
884 | } else { |
885 | $send_to = $orig_header->getAddr_s('from'); |
886 | } |
dd4a44cd |
887 | } |
73ad81bf |
888 | $send_to = decodeHeader($send_to,false,false,true); |
889 | $subject = decodeHeader($orig_header->subject,false,false,true); |
890 | $subject = str_replace('"', "'", $subject); |
891 | $subject = trim($subject); |
892 | if (substr(strtolower($subject), 0, 3) != 're:') { |
893 | $subject = 'Re: ' . $subject; |
894 | } |
895 | /* this corrects some wrapping/quoting problems on replies */ |
896 | $rewrap_body = explode("\n", $body); |
897 | $from = (is_array($orig_header->from)) ? $orig_header->from[0] : $orig_header->from; |
898 | $body = ''; |
899 | $strip_sigs = getPref($data_dir, $username, 'strip_sigs'); |
900 | foreach ($rewrap_body as $line) { |
901 | if ($strip_sigs && substr($line,0,3) == '-- ') { |
902 | break; |
903 | } |
904 | if (preg_match("/^(>+)/", $line, $matches)) { |
905 | $gt = $matches[1]; |
906 | $body .= $body_quote . str_replace("\n", "\n$body_quote$gt ", rtrim($line)) ."\n"; |
907 | } else { |
908 | $body .= $body_quote . (!empty($body_quote) ? ' ' : '') . str_replace("\n", "\n$body_quote" . (!empty($body_quote) ? ' ' : ''), rtrim($line)) . "\n"; |
909 | } |
a61878d0 |
910 | } |
c9d61baf |
911 | |
73ad81bf |
912 | //rewrap the body to clean up quotations and line lengths |
913 | $body = sqBodyWrap ($body, $editor_size); |
c9d61baf |
914 | |
73ad81bf |
915 | $body = getReplyCitation($from , $orig_header->date) . $body; |
916 | $composeMessage->reply_rfc822_header = $orig_header; |
12a0ed01 |
917 | |
73ad81bf |
918 | break; |
919 | default: |
920 | break; |
41b94d65 |
921 | } |
a91189d6 |
922 | $compose_messages[$session] = $composeMessage; |
923 | sqsession_register($compose_messages, 'compose_messages'); |
5da08ef7 |
924 | session_write_close(); |
a61878d0 |
925 | sqimap_logout($imapConnection); |
41b94d65 |
926 | } |
a61878d0 |
927 | $ret = array( 'send_to' => $send_to, |
73ad81bf |
928 | 'send_to_cc' => $send_to_cc, |
929 | 'send_to_bcc' => $send_to_bcc, |
930 | 'subject' => $subject, |
931 | 'mailprio' => $mailprio, |
932 | 'body' => $body, |
933 | 'identity' => $identity ); |
a61878d0 |
934 | |
41b94d65 |
935 | return ($ret); |
48985d59 |
936 | } /* function newMail() */ |
937 | |
50706f77 |
938 | /** |
939 | * downloads attachments from original message, stores them in attachment directory and adds |
940 | * them to composed message. |
941 | * @param object $message |
942 | * @param object $composeMessage |
943 | * @param integer $passed_id |
944 | * @param mixed $entities |
945 | * @param mixed $imapConnection |
91c27aee |
946 | * @return object |
50706f77 |
947 | */ |
a43e4b90 |
948 | function getAttachments($message, &$composeMessage, $passed_id, $entities, $imapConnection) { |
8df4c929 |
949 | global $attachment_dir, $username, $data_dir, $squirrelmail_language, $languages; |
48985d59 |
950 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
1c044820 |
951 | if (!count($message->entities) || |
73ad81bf |
952 | ($message->type0 == 'message' && $message->type1 == 'rfc822')) { |
41b94d65 |
953 | if ( !in_array($message->entity_id, $entities) && $message->entity_id) { |
73ad81bf |
954 | switch ($message->type0) { |
955 | case 'message': |
956 | if ($message->type1 == 'rfc822') { |
957 | $filename = $message->rfc822_header->subject; |
958 | if ($filename == "") { |
959 | $filename = "untitled-".$message->entity_id; |
960 | } |
961 | $filename .= '.msg'; |
962 | } else { |
963 | $filename = $message->getFilename(); |
181538ac |
964 | } |
73ad81bf |
965 | break; |
966 | default: |
967 | if (!$message->mime_header) { /* temporary hack */ |
968 | $message->mime_header = $message->header; |
969 | } |
970 | $filename = $message->getFilename(); |
971 | break; |
972 | } |
973 | $filename = str_replace(' ', ' ', decodeHeader($filename)); |
974 | if (isset($languages[$squirrelmail_language]['XTRA_CODE']) && |
975 | function_exists($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode')) { |
f4bb5d22 |
976 | $filename = call_user_func($languages[$squirrelmail_language]['XTRA_CODE'] . '_encode', $filename); |
73ad81bf |
977 | } |
978 | $localfilename = GenerateRandomString(32, '', 7); |
979 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
980 | while (file_exists($full_localfilename)) { |
981 | $localfilename = GenerateRandomString(32, '', 7); |
982 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
983 | } |
984 | $message->att_local_name = $full_localfilename; |
985 | |
986 | $composeMessage->initAttachment($message->type0.'/'.$message->type1,$filename, |
987 | $full_localfilename); |
988 | |
989 | /* Write Attachment to file */ |
990 | $fp = fopen ("$hashed_attachment_dir/$localfilename", 'wb'); |
91c27aee |
991 | mime_print_body_lines ($imapConnection, $passed_id, $message->entity_id, $message->header->encoding, $fp); |
73ad81bf |
992 | fclose ($fp); |
48985d59 |
993 | } |
734f4ee6 |
994 | } else { |
a43e4b90 |
995 | for ($i=0, $entCount=count($message->entities); $i<$entCount;$i++) { |
996 | $composeMessage=getAttachments($message->entities[$i], $composeMessage, $passed_id, $entities, $imapConnection); |
48985d59 |
997 | } |
998 | } |
a43e4b90 |
999 | return $composeMessage; |
48985d59 |
1000 | } |
1001 | |
1c044820 |
1002 | function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id, |
73ad81bf |
1003 | $passed_ent_id='', $imapConnection) { |
ce68b76b |
1004 | global $attachment_dir, $username, $data_dir; |
a6ec592e |
1005 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
756406df |
1006 | if (!$passed_ent_id) { |
1c044820 |
1007 | $body_a = sqimap_run_command($imapConnection, |
73ad81bf |
1008 | 'FETCH '.$passed_id.' RFC822', |
1009 | TRUE, $response, $readmessage, |
1010 | TRUE); |
756406df |
1011 | } else { |
1c044820 |
1012 | $body_a = sqimap_run_command($imapConnection, |
73ad81bf |
1013 | 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']', |
1014 | TRUE, $response, $readmessage, TRUE); |
a61878d0 |
1015 | $message = $message->parent; |
756406df |
1016 | } |
d0519c03 |
1017 | if ($response == 'OK') { |
a61878d0 |
1018 | $subject = encodeHeader($message->rfc822_header->subject); |
1019 | array_shift($body_a); |
1c044820 |
1020 | array_pop($body_a); |
a61878d0 |
1021 | $body = implode('', $body_a) . "\r\n"; |
1c044820 |
1022 | |
a61878d0 |
1023 | $localfilename = GenerateRandomString(32, 'FILE', 7); |
1024 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
1c044820 |
1025 | |
1026 | $fp = fopen($full_localfilename, 'w'); |
a61878d0 |
1027 | fwrite ($fp, $body); |
1028 | fclose($fp); |
5a1f1da3 |
1029 | $composeMessage->initAttachment('message/rfc822',$subject.'.msg', |
73ad81bf |
1030 | $full_localfilename); |
a43e4b90 |
1031 | } |
1032 | return $composeMessage; |
a6ec592e |
1033 | } |
1034 | |
41b94d65 |
1035 | function showInputForm ($session, $values=false) { |
ce68b76b |
1036 | global $send_to, $send_to_cc, $body, $startMessage, $action, |
1037 | $color, $use_signature, $signature, $prefix_sig, |
8d8da447 |
1038 | $editor_size, $editor_height, $subject, $newmail, |
73ad81bf |
1039 | $use_javascript_addr_book, $send_to_bcc, $passed_id, $mailbox, |
1040 | $from_htmladdr_search, $location_of_buttons, $attachment_dir, |
ce68b76b |
1041 | $username, $data_dir, $identity, $idents, $delete_draft, |
1042 | $mailprio, $compose_new_win, $saved_draft, $mail_sent, $sig_first, |
c6f28eb1 |
1043 | $compose_messages, $composesession, $default_charset, |
5c4ff7bf |
1044 | $compose_onsubmit, $oTemplate; |
a43e4b90 |
1045 | |
87745b9c |
1046 | if (checkForJavascript()) { |
1047 | $onfocus = ' onfocus="alreadyFocused=true;"'; |
1048 | $onfocus_array = array('onfocus' => 'alreadyFocused=true;'); |
1049 | } |
1050 | else { |
1051 | $onfocus = ''; |
1052 | $onfocus_array = array(); |
1053 | } |
1054 | |
a43e4b90 |
1055 | $composeMessage = $compose_messages[$session]; |
41b94d65 |
1056 | if ($values) { |
73ad81bf |
1057 | $send_to = $values['send_to']; |
1058 | $send_to_cc = $values['send_to_cc']; |
1059 | $send_to_bcc = $values['send_to_bcc']; |
1060 | $subject = $values['subject']; |
1061 | $mailprio = $values['mailprio']; |
1062 | $body = $values['body']; |
1063 | $identity = (int) $values['identity']; |
676bb189 |
1064 | } else { |
73ad81bf |
1065 | $send_to = decodeHeader($send_to, true, false); |
1066 | $send_to_cc = decodeHeader($send_to_cc, true, false); |
1067 | $send_to_bcc = decodeHeader($send_to_bcc, true, false); |
41b94d65 |
1068 | } |
1c044820 |
1069 | |
48985d59 |
1070 | if ($use_javascript_addr_book) { |
2c92ea9d |
1071 | echo "\n". '<script type="text/javascript">'."\n<!--\n" . |
73ad81bf |
1072 | 'function open_abook() { ' . "\n" . |
1073 | ' var nwin = window.open("addrbook_popup.php","abookpopup",' . |
1074 | '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" . |
1075 | ' if((!nwin.opener) && (document.windows != null))' . "\n" . |
1076 | ' nwin.opener = document.windows;' . "\n" . |
1077 | "}\n" . |
1078 | "// -->\n</script>\n\n"; |
48985d59 |
1079 | } |
1080 | |
4a1788b3 |
1081 | echo "\n" . '<form name="compose" action="compose.php" method="post" ' . |
73ad81bf |
1082 | 'enctype="multipart/form-data"'; |
a34b07a5 |
1083 | |
1084 | $compose_onsubmit = array(); |
4a1788b3 |
1085 | do_hook('compose_form'); |
1c044820 |
1086 | |
a34b07a5 |
1087 | // Plugins that use compose_form hook can add an array entry |
1088 | // to the globally scoped $compose_onsubmit; we add them up |
5c4ff7bf |
1089 | // here and format the form tag's full onsubmit handler. |
1090 | // Each plugin should use "return false" if they need to |
a34b07a5 |
1091 | // stop form submission but otherwise should NOT use "return |
1092 | // true" to give other plugins the chance to do what they need |
1093 | // to do; SquirrelMail itself will add the final "return true". |
1094 | // Onsubmit text is enclosed inside of double quotes, so plugins |
1095 | // need to quote accordingly. |
1096 | if (checkForJavascript()) { |
1097 | $onsubmit_text = ' onsubmit="'; |
5c4ff7bf |
1098 | if (empty($compose_onsubmit)) |
a34b07a5 |
1099 | $compose_onsubmit = array(); |
5c4ff7bf |
1100 | else if (!is_array($compose_onsubmit)) |
a34b07a5 |
1101 | $compose_onsubmit = array($compose_onsubmit); |
1102 | |
1103 | foreach ($compose_onsubmit as $text) { |
1104 | $text = trim($text); |
5c4ff7bf |
1105 | if (substr($text, -1) != ';' && substr($text, -1) != '}') |
a34b07a5 |
1106 | $text .= '; '; |
1107 | $onsubmit_text .= $text; |
1108 | } |
1109 | |
1110 | echo $onsubmit_text . ' return true;"'; |
1111 | } |
5c4ff7bf |
1112 | |
a34b07a5 |
1113 | |
48985d59 |
1114 | echo ">\n"; |
1115 | |
df96b37a |
1116 | echo addHidden('startMessage', $startMessage); |
4a1788b3 |
1117 | |
41b94d65 |
1118 | if ($action == 'draft') { |
df96b37a |
1119 | echo addHidden('delete_draft', $passed_id); |
48985d59 |
1120 | } |
1121 | if (isset($delete_draft)) { |
df96b37a |
1122 | echo addHidden('delete_draft', $delete_draft); |
48985d59 |
1123 | } |
da95c4b6 |
1124 | if (isset($session)) { |
df96b37a |
1125 | echo addHidden('session', $session); |
da95c4b6 |
1126 | } |
1c044820 |
1127 | |
08bad2b1 |
1128 | if (isset($passed_id)) { |
df96b37a |
1129 | echo addHidden('passed_id', $passed_id); |
08bad2b1 |
1130 | } |
44560457 |
1131 | |
9c3e6cd4 |
1132 | if ($saved_draft == 'yes') { |
f265009a |
1133 | echo '<br /><div style="text-align: center;"><b>'. _("Draft Saved").'</div></b>'; |
9c3e6cd4 |
1134 | } |
1135 | if ($mail_sent == 'yes') { |
f265009a |
1136 | echo '<br /><div style="text-align: center;"><b>'. _("Your Message has been sent.").'</div></b>'; |
9c3e6cd4 |
1137 | } |
9c3e6cd4 |
1138 | if ($compose_new_win == '1') { |
39bfea8f |
1139 | echo '<table align="center" bgcolor="'.$color[0].'" width="100%" border="0">'."\n" . |
73ad81bf |
1140 | ' <tr><td></td>'.html_tag( 'td', '', 'right' ). |
6fc2ba92 |
1141 | '<input type="button" name="Close" onclick="return self.close()" value="'. |
73ad81bf |
1142 | _("Close").'" /></td></tr>'."\n"; |
bfa54da7 |
1143 | } else { |
1144 | echo '<table align="center" cellspacing="0" border="0">' . "\n"; |
9c3e6cd4 |
1145 | } |
78a35fcd |
1146 | if ($location_of_buttons == 'top') { |
1147 | showComposeButtonRow(); |
1148 | } |
48985d59 |
1149 | |
0f257091 |
1150 | /* display select list for identities */ |
1e2a6ff6 |
1151 | if (count($idents) > 1) { |
73ad81bf |
1152 | $ident_list = array(); |
1153 | foreach($idents as $id => $data) { |
1154 | $ident_list[$id] = |
1155 | $data['full_name'].' <'.$data['email_address'].'>'; |
1156 | } |
0f257091 |
1157 | echo ' <tr>' . "\n" . |
73ad81bf |
1158 | html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) . |
828c58f1 |
1159 | '<label for="identity">' . _("From:") . '</label></td>' . "\n" . |
73ad81bf |
1160 | html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) . |
1161 | ' '. |
1162 | addSelect('identity', $ident_list, $identity, TRUE); |
1e2a6ff6 |
1163 | |
df96b37a |
1164 | echo ' </td>' . "\n" . |
73ad81bf |
1165 | ' </tr>' . "\n"; |
41b94d65 |
1166 | } |
46f2284f |
1167 | |
0f257091 |
1168 | echo ' <tr>' . "\n" . |
73ad81bf |
1169 | html_tag( 'td', '', 'right', $color[4], 'width="10%"' ) . |
828c58f1 |
1170 | '<label for="send_to">' . _("To") . '</label>:</td>' . "\n" . |
73ad81bf |
1171 | html_tag( 'td', '', 'left', $color[4], 'width="90%"' ) . |
87745b9c |
1172 | addInput('send_to', $send_to, 60, 0, $onfocus_array). '<br />' . "\n" . |
73ad81bf |
1173 | ' </td>' . "\n" . |
1174 | ' </tr>' . "\n" . |
1175 | ' <tr>' . "\n" . |
1176 | html_tag( 'td', '', 'right', $color[4] ) . |
828c58f1 |
1177 | '<label for="send_to_cc">' . _("Cc") . '</label>:</td>' . "\n" . |
73ad81bf |
1178 | html_tag( 'td', '', 'left', $color[4] ) . |
87745b9c |
1179 | addInput('send_to_cc', $send_to_cc, 60, 0, $onfocus_array). '<br />' . "\n" . |
73ad81bf |
1180 | ' </td>' . "\n" . |
1181 | ' </tr>' . "\n" . |
1182 | ' <tr>' . "\n" . |
1183 | html_tag( 'td', '', 'right', $color[4] ) . |
828c58f1 |
1184 | '<label for="send_to_bcc">' . _("Bcc") . '</label>:</td>' . "\n" . |
73ad81bf |
1185 | html_tag( 'td', '', 'left', $color[4] ) . |
87745b9c |
1186 | addInput('send_to_bcc', $send_to_bcc, 60, 0, $onfocus_array).'<br />' . "\n" . |
73ad81bf |
1187 | ' </td>' . "\n" . |
1188 | ' </tr>' . "\n" . |
1189 | ' <tr>' . "\n" . |
1190 | html_tag( 'td', '', 'right', $color[4] ) . |
828c58f1 |
1191 | '<label for="subject">' . _("Subject") . '</label>:</td>' . "\n" . |
73ad81bf |
1192 | html_tag( 'td', '', 'left', $color[4] ) . "\n"; |
87745b9c |
1193 | echo ' '.addInput('subject', $subject, 60, 0, $onfocus_array). |
73ad81bf |
1194 | ' </td>' . "\n" . |
1195 | ' </tr>' . "\n\n"; |
48985d59 |
1196 | |
78a35fcd |
1197 | if ($location_of_buttons == 'between') { |
1198 | showComposeButtonRow(); |
1199 | } |
4dfb9db7 |
1200 | |
0d73f4ee |
1201 | /** |
1202 | * When message is compose in new window, different colors are used. |
1203 | */ |
fdc83c55 |
1204 | if ($compose_new_win == '1') { |
39bfea8f |
1205 | echo ' <tr>' . "\n" . |
73ad81bf |
1206 | ' <td bgcolor="' . $color[0] . '" colspan="2" align="center">' . "\n" . |
1207 | ' <textarea name="body" id="body" rows="' . (int)$editor_height . |
0d73f4ee |
1208 | '" cols="' . (int)$editor_size . '"' . $onfocus . '>'; |
fdc83c55 |
1209 | } |
1210 | else { |
39bfea8f |
1211 | echo ' <tr>' . "\n" . |
1212 | ' <td bgcolor="' . $color[4] . '" colspan="2">' . "\n" . |
1213 | ' <textarea name="body" id="body" rows="' . (int)$editor_height . |
0d73f4ee |
1214 | '" cols="' . (int)$editor_size . '"' . $onfocus . '>'; |
fdc83c55 |
1215 | } |
0f257091 |
1216 | |
48985d59 |
1217 | if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) { |
1e2a6ff6 |
1218 | $signature = $idents[$identity]['signature']; |
d3c13a51 |
1219 | |
3b17e952 |
1220 | if ($sig_first == '1') { |
50706f77 |
1221 | /* |
1222 | * FIXME: test is specific to ja_JP translation implementation. |
1223 | * This test might apply incorrect conversion to other translations, but |
91c27aee |
1224 | * use of 7bit iso-2022-jp charset in other translations might have other |
50706f77 |
1225 | * issues too. |
1226 | */ |
ab4700c3 |
1227 | if ($default_charset == 'iso-2022-jp') { |
83be314a |
1228 | echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP'); |
1229 | } else { |
73ad81bf |
1230 | echo "\n\n".($prefix_sig==true? "-- \n":'').decodeHeader($signature,false,false); |
83be314a |
1231 | } |
df96b37a |
1232 | echo "\n\n".htmlspecialchars(decodeHeader($body,false,false)); |
3b17e952 |
1233 | } |
1234 | else { |
df96b37a |
1235 | echo "\n\n".htmlspecialchars(decodeHeader($body,false,false)); |
50706f77 |
1236 | // FIXME: test is specific to ja_JP translation implementation. See above comments. |
ab4700c3 |
1237 | if ($default_charset == 'iso-2022-jp') { |
83be314a |
1238 | echo "\n\n".($prefix_sig==true? "-- \n":'').mb_convert_encoding($signature, 'EUC-JP'); |
1239 | }else{ |
73ad81bf |
1240 | echo "\n\n".($prefix_sig==true? "-- \n":'').decodeHeader($signature,false,false); |
1241 | } |
3b17e952 |
1242 | } |
73ad81bf |
1243 | } else { |
1244 | echo htmlspecialchars(decodeHeader($body,false,false)); |
48985d59 |
1245 | } |
0f257091 |
1246 | echo '</textarea><br />' . "\n" . |
73ad81bf |
1247 | ' </td>' . "\n" . |
1248 | ' </tr>' . "\n"; |
48985d59 |
1249 | |
12a0ed01 |
1250 | |
48985d59 |
1251 | if ($location_of_buttons == 'bottom') { |
1252 | showComposeButtonRow(); |
1253 | } else { |
0f257091 |
1254 | echo ' <tr>' . "\n" . |
73ad81bf |
1255 | html_tag( 'td', '', 'right', '', 'colspan="2"' ) . "\n" . |
1256 | ' ' . addSubmit(_("Send"), 'send'). |
1257 | ' <br /><br />' . "\n" . |
1258 | ' </td>' . "\n" . |
1259 | ' </tr>' . "\n"; |
48985d59 |
1260 | } |
46bb8da8 |
1261 | |
48985d59 |
1262 | /* This code is for attachments */ |
73ad81bf |
1263 | if ((bool) ini_get('file_uploads')) { |
1264 | |
1265 | /* Calculate the max size for an uploaded file. |
1266 | * This is advisory for the user because we can't actually prevent |
1267 | * people to upload too large files. */ |
1268 | $sizes = array(); |
1269 | /* php.ini vars which influence the max for uploads */ |
1270 | $configvars = array('post_max_size', 'memory_limit', 'upload_max_filesize'); |
1271 | foreach($configvars as $var) { |
4f21ba00 |
1272 | /* skip 0 or empty values, and -1 which means 'unlimited' */ |
73ad81bf |
1273 | if( $size = getByteSize(ini_get($var)) ) { |
4f21ba00 |
1274 | if ( $size != '-1' ) { |
1275 | $sizes[] = $size; |
1276 | } |
73ad81bf |
1277 | } |
0a2c3218 |
1278 | } |
0a2c3218 |
1279 | |
73ad81bf |
1280 | if(count($sizes) > 0) { |
0321108e |
1281 | $maxsize = '(max. ' . show_readable_size( min( $sizes ) ) . ')' |
202bcbcc |
1282 | . addHidden('MAX_FILE_SIZE', min( $sizes )); |
73ad81bf |
1283 | } else { |
1284 | $maxsize = ''; |
1285 | } |
4f21ba00 |
1286 | echo ' <tr>' . "\n" . |
73ad81bf |
1287 | ' <td colspan="2">' . "\n" . |
1288 | ' <table width="100%" cellpadding="1" cellspacing="0" align="center"'. |
1289 | ' border="0" bgcolor="'.$color[9].'">' . "\n" . |
1290 | ' <tr>' . "\n" . |
1291 | ' <td>' . "\n" . |
1292 | ' <table width="100%" cellpadding="3" cellspacing="0" align="center"'. |
1293 | ' border="0">' . "\n" . |
1294 | ' <tr>' . "\n" . |
1295 | html_tag( 'td', '', 'right', '', 'valign="middle"' ) . |
1296 | _("Attach:") . '</td>' . "\n" . |
1297 | html_tag( 'td', '', 'left', '', 'valign="middle"' ) . |
1298 | ' <input name="attachfile" size="48" type="file" />' . "\n" . |
1299 | ' <input type="submit" name="attach"' . |
1300 | ' value="' . _("Add") .'" />' . "\n" . |
1301 | $maxsize . |
1302 | ' </td>' . "\n" . |
1303 | ' </tr>' . "\n"; |
1304 | |
1305 | $s_a = array(); |
1306 | if ($composeMessage->entities) { |
1307 | foreach ($composeMessage->entities as $key => $attachment) { |
1308 | $attached_file = $attachment->att_local_name; |
1309 | if ($attachment->att_local_name || $attachment->body_part) { |
1310 | $attached_filename = decodeHeader($attachment->mime_header->getParameter('name')); |
1311 | $type = $attachment->mime_header->type0.'/'. |
a91189d6 |
1312 | $attachment->mime_header->type1; |
1c044820 |
1313 | |
73ad81bf |
1314 | $s_a[] = '<table bgcolor="'.$color[0]. |
1315 | '" border="0"><tr><td>'. |
1316 | addCheckBox('delete[]', FALSE, $key). |
1317 | "</td><td>\n" . $attached_filename . |
1318 | '</td><td>-</td><td> ' . $type . '</td><td>('. |
1319 | show_readable_size( filesize( $attached_file ) ) . ')</td></tr></table>'."\n"; |
1320 | } |
1321 | } |
4dfb9db7 |
1322 | } |
73ad81bf |
1323 | if (count($s_a)) { |
1324 | foreach ($s_a as $s) { |
1325 | echo '<tr>' . html_tag( 'td', '', 'left', $color[0], 'colspan="2"' ) . $s .'</td></tr>'; |
1326 | } |
1327 | echo '<tr><td colspan="2"><input type="submit" name="do_delete" value="' . |
1328 | _("Delete selected attachments") . "\" />\n" . |
1329 | '</td></tr>'; |
1330 | } |
1331 | echo ' </table>' . "\n" . |
1332 | ' </td>' . "\n" . |
1333 | ' </tr>' . "\n" . |
1334 | ' </table>' . "\n" . |
1335 | ' </td>' . "\n" . |
1336 | ' </tr>' . "\n"; |
1337 | } // End of file_uploads if-block |
41b94d65 |
1338 | /* End of attachment code */ |
39bfea8f |
1339 | echo '</table>' . "\n" . |
0fa24cb6 |
1340 | addHidden('username', $username). |
1341 | addHidden('smaction', $action). |
1342 | addHidden('mailbox', $mailbox); |
1c044820 |
1343 | /* |
1344 | store the complete ComposeMessages array in a hidden input value |
0ec1a14b |
1345 | so we can restore them in case of a session timeout. |
73ad81bf |
1346 | */ |
953fa718 |
1347 | sqgetGlobalVar('QUERY_STRING', $queryString, SQ_SERVER); |
df96b37a |
1348 | echo addHidden('restoremessages', serialize($compose_messages)). |
73ad81bf |
1349 | addHidden('composesession', $composesession). |
1350 | addHidden('querystring', $queryString). |
1351 | "</form>\n"; |
a64f47e7 |
1352 | if (!(bool) ini_get('file_uploads')) { |
73ad81bf |
1353 | /* File uploads are off, so we didn't show that part of the form. |
1354 | To avoid bogus bug reports, tell the user why. */ |
50706f77 |
1355 | echo '<p style="text-align:center">' |
1356 | . _("Because PHP file uploads are turned off, you can not attach files to this message. Please see your system administrator for details.") |
1357 | . "</p>\r\n"; |
a64f47e7 |
1358 | } |
1359 | |
9f599fe3 |
1360 | do_hook('compose_bottom'); |
5c4ff7bf |
1361 | $oTemplate->display('footer.tpl'); |
48985d59 |
1362 | } |
1363 | |
1364 | |
70c4fd84 |
1365 | function showComposeButtonRow() { |
78a35fcd |
1366 | global $use_javascript_addr_book, $save_as_draft, |
73ad81bf |
1367 | $default_use_priority, $mailprio, $default_use_mdn, |
1368 | $request_mdn, $request_dr, |
1369 | $data_dir, $username; |
70c4fd84 |
1370 | |
39bfea8f |
1371 | echo ' <tr>' . "\n" . |
73ad81bf |
1372 | ' <td></td>' . "\n" . |
1373 | ' <td>' . "\n"; |
ae25968c |
1374 | if ($default_use_priority) { |
1375 | if(!isset($mailprio)) { |
df96b37a |
1376 | $mailprio = '3'; |
1377 | } |
828c58f1 |
1378 | echo ' <label for="mailprio">' . _("Priority") . '</label>: '. |
73ad81bf |
1379 | addSelect('mailprio', array( |
1380 | '1' => _("High"), |
1381 | '3' => _("Normal"), |
1382 | '5' => _("Low") ), $mailprio, TRUE); |
ae25968c |
1383 | } |
1384 | $mdn_user_support=getPref($data_dir, $username, 'mdn_user_support',$default_use_mdn); |
1385 | if ($default_use_mdn) { |
70c4fd84 |
1386 | if ($mdn_user_support) { |
0ec1a14b |
1387 | echo ' ' . _("Receipt") .': '. |
828c58f1 |
1388 | addCheckBox('request_mdn', $request_mdn == '1', '1') . |
1389 | '<label for="request_mdn">' . _("On Read") . '</label>' . |
1390 | addCheckBox('request_dr', $request_dr == '1', '1') . |
1391 | '<label for="request_dr">' . _("On Delivery") . '</label>'; |
70c4fd84 |
1392 | } |
ae25968c |
1393 | } |
48985d59 |
1394 | |
39bfea8f |
1395 | echo ' </td>' . "\n" . |
73ad81bf |
1396 | ' </tr>' . "\n" . |
1397 | ' <tr>' . "\n" . |
1398 | ' <td></td>' . "\n" . |
1399 | ' <td>' . "\n" . |
1400 | ' <input type="submit" name="sigappend" value="' . _("Signature") . '" />' . "\n"; |
78a35fcd |
1401 | if ($use_javascript_addr_book) { |
2c92ea9d |
1402 | echo " <script type=\"text/javascript\"><!--\n document.write(\"". |
73ad81bf |
1403 | " <input type=button value=\\\""._("Addresses"). |
1404 | "\\\" onclick=\\\"javascript:open_abook();\\\" />\");". |
1405 | " // --></script><noscript>\n". |
1406 | ' <input type="submit" name="html_addr_search" value="'. |
1407 | _("Addresses").'" />'. |
1408 | " </noscript>\n"; |
734f4ee6 |
1409 | } else { |
39bfea8f |
1410 | echo ' <input type="submit" name="html_addr_search" value="'. |
73ad81bf |
1411 | _("Addresses").'" />' . "\n"; |
78a35fcd |
1412 | } |
48985d59 |
1413 | |
78a35fcd |
1414 | if ($save_as_draft) { |
39bfea8f |
1415 | echo ' <input type="submit" name ="draft" value="' . _("Save Draft") . "\" />\n"; |
78a35fcd |
1416 | } |
0a17f9dd |
1417 | |
39bfea8f |
1418 | echo ' <input type="submit" name="send" value="'. _("Send") . '" />' . "\n"; |
78a35fcd |
1419 | do_hook('compose_button_row'); |
441f2d33 |
1420 | |
39bfea8f |
1421 | echo ' </td>' . "\n" . |
73ad81bf |
1422 | ' </tr>' . "\n\n"; |
78a35fcd |
1423 | } |
b278172f |
1424 | |
70c4fd84 |
1425 | function checkInput ($show) { |
78a35fcd |
1426 | /* |
1427 | * I implemented the $show variable because the error messages |
1428 | * were getting sent before the page header. So, I check once |
1429 | * using $show=false, and then when i'm ready to display the error |
1430 | * message, show=true |
1431 | */ |
c6f28eb1 |
1432 | global $send_to, $send_to_bcc; |
78a35fcd |
1433 | |
6bf2a88f |
1434 | if ($send_to == '' && $send_to_bcc == '') { |
78a35fcd |
1435 | if ($show) { |
cb34dbd0 |
1436 | plain_error_message(_("You have not filled in the \"To:\" field.")); |
78a35fcd |
1437 | } |
1438 | return false; |
1439 | } |
1440 | return true; |
1441 | } /* function checkInput() */ |
df15de21 |
1442 | |
3806fa52 |
1443 | |
00793a25 |
1444 | /* True if FAILURE */ |
da95c4b6 |
1445 | function saveAttachedFiles($session) { |
c077ffeb |
1446 | global $_FILES, $attachment_dir, $username, |
73ad81bf |
1447 | $data_dir, $compose_messages; |
bfa54da7 |
1448 | |
45cdd1b5 |
1449 | /* get out of here if no file was attached at all */ |
1450 | if (! is_uploaded_file($_FILES['attachfile']['tmp_name']) ) { |
1451 | return true; |
1452 | } |
1453 | |
4c9d2242 |
1454 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
1455 | $localfilename = GenerateRandomString(32, '', 7); |
1456 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
1457 | while (file_exists($full_localfilename)) { |
1458 | $localfilename = GenerateRandomString(32, '', 7); |
1459 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
1460 | } |
1461 | |
a42c236f |
1462 | // m_u_f works better with restricted PHP installs (safe_mode, open_basedir), |
1463 | // if that doesn't work, try a simple rename. |
1464 | if (!@move_uploaded_file($_FILES['attachfile']['tmp_name'],$full_localfilename)) { |
1465 | if (!@rename($_FILES['attachfile']['tmp_name'], $full_localfilename)) { |
73ad81bf |
1466 | return true; |
1467 | } |
a61878d0 |
1468 | } |
a43e4b90 |
1469 | $message = $compose_messages[$session]; |
0b97a708 |
1470 | $type = strtolower($_FILES['attachfile']['type']); |
1471 | $name = $_FILES['attachfile']['name']; |
a43e4b90 |
1472 | $message->initAttachment($type, $name, $full_localfilename); |
1473 | $compose_messages[$session] = $message; |
b0314f04 |
1474 | sqsession_register($compose_messages , 'compose_messages'); |
4c9d2242 |
1475 | } |
1476 | |
0a2c3218 |
1477 | /* parse values like 8M and 2k into bytes */ |
1478 | function getByteSize($ini_size) { |
1479 | |
4d30dc83 |
1480 | if(!$ini_size) { |
1481 | return FALSE; |
1482 | } |
da95c4b6 |
1483 | |
0a2c3218 |
1484 | $ini_size = trim($ini_size); |
1485 | |
5b9716de |
1486 | // if there's some kind of letter at the end of the string we need to multiply. |
1487 | if(!is_numeric(substr($ini_size, -1))) { |
1488 | |
1489 | switch(strtoupper(substr($ini_size, -1))) { |
1490 | case 'G': |
73ad81bf |
1491 | $bytesize = 1073741824; |
1492 | break; |
5b9716de |
1493 | case 'M': |
73ad81bf |
1494 | $bytesize = 1048576; |
1495 | break; |
5b9716de |
1496 | case 'K': |
73ad81bf |
1497 | $bytesize = 1024; |
1498 | break; |
5b9716de |
1499 | } |
1500 | |
4d30dc83 |
1501 | return ($bytesize * (int)substr($ini_size, 0, -1)); |
0a2c3218 |
1502 | } |
1c044820 |
1503 | |
4d30dc83 |
1504 | return $ini_size; |
0a2c3218 |
1505 | } |
a43e4b90 |
1506 | |
4c9d2242 |
1507 | |
50706f77 |
1508 | /** |
1509 | * temporary function to make use of the deliver class. |
a42c236f |
1510 | * In the future the responsible backend should be automaticly loaded |
50706f77 |
1511 | * and conf.pl should show a list of available backends. |
1512 | * The message also should be constructed by the message class. |
73ad81bf |
1513 | */ |
b7ff469f |
1514 | function deliverMessage($composeMessage, $draft=false) { |
a43e4b90 |
1515 | global $send_to, $send_to_cc, $send_to_bcc, $mailprio, $subject, $body, |
73ad81bf |
1516 | $username, $popuser, $usernamedata, $identity, $idents, $data_dir, |
1517 | $request_mdn, $request_dr, $default_charset, $color, $useSendmail, |
1518 | $domain, $action, $default_move_to_sent, $move_to_sent; |
a43e4b90 |
1519 | global $imapServerAddress, $imapPort, $sent_folder, $key; |
1520 | |
1521 | $rfc822_header = $composeMessage->rfc822_header; |
24192f77 |
1522 | |
1523 | $abook = addressbook_init(false, true); |
310dfeb6 |
1524 | $rfc822_header->to = $rfc822_header->parseAddress($send_to,true, array(), '', $domain, array(&$abook,'lookup')); |
1525 | $rfc822_header->cc = $rfc822_header->parseAddress($send_to_cc,true,array(), '',$domain, array(&$abook,'lookup')); |
1526 | $rfc822_header->bcc = $rfc822_header->parseAddress($send_to_bcc,true, array(), '',$domain, array(&$abook,'lookup')); |
a43e4b90 |
1527 | $rfc822_header->priority = $mailprio; |
1528 | $rfc822_header->subject = $subject; |
310dfeb6 |
1529 | |
a43e4b90 |
1530 | $special_encoding=''; |
1531 | if (strtolower($default_charset) == 'iso-2022-jp') { |
1532 | if (mb_detect_encoding($body) == 'ASCII') { |
a91189d6 |
1533 | $special_encoding = '8bit'; |
a43e4b90 |
1534 | } else { |
1535 | $body = mb_convert_encoding($body, 'JIS'); |
1536 | $special_encoding = '7bit'; |
1537 | } |
1538 | } |
1539 | $composeMessage->setBody($body); |
1540 | |
1541 | if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) { |
73ad81bf |
1542 | $popuser = $usernamedata[1]; |
1543 | $domain = $usernamedata[2]; |
1544 | unset($usernamedata); |
a43e4b90 |
1545 | } else { |
73ad81bf |
1546 | $popuser = $username; |
a43e4b90 |
1547 | } |
1548 | $reply_to = ''; |
1e2a6ff6 |
1549 | $from_mail = $idents[$identity]['email_address']; |
1550 | $full_name = $idents[$identity]['full_name']; |
1551 | $reply_to = $idents[$identity]['reply_to']; |
9ca455db |
1552 | if (!$from_mail) { |
73ad81bf |
1553 | $from_mail = "$popuser@$domain"; |
045714fd |
1554 | } |
1555 | $rfc822_header->from = $rfc822_header->parseAddress($from_mail,true); |
1556 | if ($full_name) { |
9783f396 |
1557 | $from = $rfc822_header->from[0]; |
a91189d6 |
1558 | if (!$from->host) $from->host = $domain; |
12a0ed01 |
1559 | $full_name_encoded = encodeHeader($full_name); |
1560 | if ($full_name_encoded != $full_name) { |
1561 | $from_addr = $full_name_encoded .' <'.$from->mailbox.'@'.$from->host.'>'; |
1562 | } else { |
1563 | $from_addr = '"'.$full_name .'" <'.$from->mailbox.'@'.$from->host.'>'; |
1564 | } |
045714fd |
1565 | $rfc822_header->from = $rfc822_header->parseAddress($from_addr,true); |
a43e4b90 |
1566 | } |
a43e4b90 |
1567 | if ($reply_to) { |
73ad81bf |
1568 | $rfc822_header->reply_to = $rfc822_header->parseAddress($reply_to,true); |
a43e4b90 |
1569 | } |
1570 | /* Receipt: On Read */ |
1571 | if (isset($request_mdn) && $request_mdn) { |
73ad81bf |
1572 | $rfc822_header->dnt = $rfc822_header->parseAddress($from_mail,true); |
a43e4b90 |
1573 | } |
1574 | /* Receipt: On Delivery */ |
1575 | if (isset($request_dr) && $request_dr) { |
73ad81bf |
1576 | $rfc822_header->more_headers['Return-Receipt-To'] = $from_mail; |
a43e4b90 |
1577 | } |
1578 | /* multipart messages */ |
1579 | if (count($composeMessage->entities)) { |
1580 | $message_body = new Message(); |
a91189d6 |
1581 | $message_body->body_part = $composeMessage->body_part; |
1582 | $composeMessage->body_part = ''; |
1583 | $mime_header = new MessageHeader; |
1584 | $mime_header->type0 = 'text'; |
1585 | $mime_header->type1 = 'plain'; |
1586 | if ($special_encoding) { |
1587 | $mime_header->encoding = $special_encoding; |
1c044820 |
1588 | } else { |
12a0ed01 |
1589 | $mime_header->encoding = '8bit'; |
a91189d6 |
1590 | } |
1591 | if ($default_charset) { |
1592 | $mime_header->parameters['charset'] = $default_charset; |
1593 | } |
1c044820 |
1594 | $message_body->mime_header = $mime_header; |
a43e4b90 |
1595 | array_unshift($composeMessage->entities, $message_body); |
a91189d6 |
1596 | $content_type = new ContentType('multipart/mixed'); |
a43e4b90 |
1597 | } else { |
1e2026df |
1598 | $content_type = new ContentType('text/plain'); |
1599 | if ($special_encoding) { |
1600 | $rfc822_header->encoding = $special_encoding; |
1c044820 |
1601 | } else { |
1e2026df |
1602 | $rfc822_header->encoding = '8bit'; |
1c044820 |
1603 | } |
426e0b72 |
1604 | if ($default_charset) { |
1605 | $content_type->properties['charset']=$default_charset; |
73ad81bf |
1606 | } |
181538ac |
1607 | } |
1c044820 |
1608 | |
a43e4b90 |
1609 | $rfc822_header->content_type = $content_type; |
1610 | $composeMessage->rfc822_header = $rfc822_header; |
181538ac |
1611 | |
1c044820 |
1612 | /* Here you can modify the message structure just before we hand |
5618924b |
1613 | it over to deliver */ |
5255585d |
1614 | $hookReturn = do_hook('compose_send', $composeMessage); |
1615 | /* Get any changes made by plugins to $composeMessage. */ |
1616 | if ( is_object($hookReturn[1]) ) { |
1617 | $composeMessage = $hookReturn[1]; |
1618 | } |
a43e4b90 |
1619 | |
b48d3c53 |
1620 | if (!$useSendmail && !$draft) { |
a91189d6 |
1621 | require_once(SM_PATH . 'class/deliver/Deliver_SMTP.class.php'); |
1622 | $deliver = new Deliver_SMTP(); |
ce68b76b |
1623 | global $smtpServerAddress, $smtpPort, $pop_before_smtp; |
a91189d6 |
1624 | |
a91189d6 |
1625 | $authPop = (isset($pop_before_smtp) && $pop_before_smtp) ? true : false; |
9bd3b1e6 |
1626 | get_smtp_user($user, $pass); |
a91189d6 |
1627 | $stream = $deliver->initStream($composeMessage,$domain,0, |
73ad81bf |
1628 | $smtpServerAddress, $smtpPort, $user, $pass, $authPop); |
b48d3c53 |
1629 | } elseif (!$draft) { |
73ad81bf |
1630 | require_once(SM_PATH . 'class/deliver/Deliver_SendMail.class.php'); |
fd7ab795 |
1631 | global $sendmail_path, $sendmail_args; |
f3dc9c62 |
1632 | // Check for outdated configuration |
1633 | if (!isset($sendmail_args)) { |
1634 | if ($sendmail_path=='/var/qmail/bin/qmail-inject') { |
1635 | $sendmail_args = ''; |
1636 | } else { |
1637 | $sendmail_args = '-i -t'; |
1638 | } |
1639 | } |
fd7ab795 |
1640 | $deliver = new Deliver_SendMail(array('sendmail_args'=>$sendmail_args)); |
73ad81bf |
1641 | $stream = $deliver->initStream($composeMessage,$sendmail_path); |
b48d3c53 |
1642 | } elseif ($draft) { |
73ad81bf |
1643 | global $draft_folder; |
1644 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
1645 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, |
1646 | $imapPort, 0); |
1647 | if (sqimap_mailbox_exists ($imap_stream, $draft_folder)) { |
1648 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
1649 | $imap_deliver = new Deliver_IMAP(); |
1650 | $length = $imap_deliver->mail($composeMessage); |
1651 | sqimap_append ($imap_stream, $draft_folder, $length); |
1652 | $imap_deliver->mail($composeMessage, $imap_stream); |
1653 | sqimap_append_done ($imap_stream, $draft_folder); |
1654 | sqimap_logout($imap_stream); |
1655 | unset ($imap_deliver); |
c077ffeb |
1656 | $composeMessage->purgeAttachments(); |
73ad81bf |
1657 | return $length; |
4dfb9db7 |
1658 | } else { |
fd7ab795 |
1659 | $msg = '<br />'.sprintf(_("Error: Draft folder %s does not exist."), htmlspecialchars($draft_folder)); |
cb34dbd0 |
1660 | plain_error_message($msg); |
73ad81bf |
1661 | return false; |
a91189d6 |
1662 | } |
a43e4b90 |
1663 | } |
0c59bbe1 |
1664 | $success = false; |
a43e4b90 |
1665 | if ($stream) { |
a91189d6 |
1666 | $length = $deliver->mail($composeMessage, $stream); |
0c59bbe1 |
1667 | $success = $deliver->finalizeStream($stream); |
a43e4b90 |
1668 | } |
0c59bbe1 |
1669 | if (!$success) { |
fd7ab795 |
1670 | // $deliver->dlv_server_msg is not always server's reply |
a15f9d93 |
1671 | $msg = $deliver->dlv_msg; |
1672 | if (!empty($deliver->dlv_server_msg)) { |
1673 | // add 'server replied' part only when it is not empty. |
1674 | // Delivery error can be generated by delivery class itself |
1675 | $msg.='<br />' . |
1676 | _("Server replied:") . ' ' . $deliver->dlv_ret_nr . ' ' . |
1677 | nl2br(htmlspecialchars($deliver->dlv_server_msg)); |
1678 | } |
cb34dbd0 |
1679 | plain_error_message($msg); |
a43e4b90 |
1680 | } else { |
1681 | unset ($deliver); |
20152d80 |
1682 | $move_to_sent = getPref($data_dir,$username,'move_to_sent'); |
1683 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
e4a1f097 |
1684 | |
1685 | /* Move to sent code */ |
1686 | if (isset($default_move_to_sent) && ($default_move_to_sent != 0)) { |
1687 | $svr_allow_sent = true; |
1688 | } else { |
1689 | $svr_allow_sent = false; |
1690 | } |
1691 | |
1c044820 |
1692 | if (isset($sent_folder) && (($sent_folder != '') || ($sent_folder != 'none')) |
73ad81bf |
1693 | && sqimap_mailbox_exists( $imap_stream, $sent_folder)) { |
e4a1f097 |
1694 | $fld_sent = true; |
1695 | } else { |
1696 | $fld_sent = false; |
1697 | } |
1698 | |
1699 | if ((isset($move_to_sent) && ($move_to_sent != 0)) || (!isset($move_to_sent))) { |
1700 | $lcl_allow_sent = true; |
1701 | } else { |
1702 | $lcl_allow_sent = false; |
1703 | } |
1704 | |
1705 | if (($fld_sent && $svr_allow_sent && !$lcl_allow_sent) || ($fld_sent && $lcl_allow_sent)) { |
eceefdfe |
1706 | global $passed_id, $mailbox, $action; |
1707 | if ($action == 'reply' || $action == 'reply_all') { |
1708 | $save_reply_with_orig=getPref($data_dir,$username,'save_reply_with_orig'); |
1709 | if ($save_reply_with_orig) { |
1710 | $sent_folder = $mailbox; |
1711 | } |
1712 | } |
e4a1f097 |
1713 | sqimap_append ($imap_stream, $sent_folder, $length); |
a91189d6 |
1714 | require_once(SM_PATH . 'class/deliver/Deliver_IMAP.class.php'); |
1715 | $imap_deliver = new Deliver_IMAP(); |
1716 | $imap_deliver->mail($composeMessage, $imap_stream); |
e4a1f097 |
1717 | sqimap_append_done ($imap_stream, $sent_folder); |
a91189d6 |
1718 | unset ($imap_deliver); |
1719 | } |
8780308f |
1720 | |
1721 | global $passed_id, $mailbox, $action, $what, $iAccount,$startMessage; |
1722 | |
c077ffeb |
1723 | $composeMessage->purgeAttachments(); |
a91189d6 |
1724 | if ($action == 'reply' || $action == 'reply_all') { |
202bcbcc |
1725 | require(SM_PATH . 'functions/mailbox_display.php'); |
8780308f |
1726 | $aMailbox = sqm_api_mailbox_select($imap_stream, $iAccount, $mailbox,array('setindex' => $what, 'offset' => $startMessage),array()); |
bda07b93 |
1727 | // check if we are allowed to set the \\Answered flag |
1728 | if (in_array('\\answered',$aMailbox['PERMANENTFLAGS'], true)) { |
1729 | $aUpdatedMsgs = sqimap_toggle_flag($imap_stream, array($passed_id), '\\Answered', true, false); |
1730 | if (isset($aUpdatedMsgs[$passed_id]['FLAGS'])) { |
1731 | /** |
1732 | * Only update the cached headers if the header is |
1733 | * cached. |
1734 | */ |
1735 | if (isset($aMailbox['MSG_HEADERS'][$passed_id])) { |
1736 | $aMailbox['MSG_HEADERS'][$passed_id]['FLAGS'] = $aMsg['FLAGS']; |
1737 | } |
8780308f |
1738 | } |
1739 | } |
4d1cb59a |
1740 | /** |
1741 | * Write mailbox with updated seen flag information back to cache. |
1742 | */ |
1743 | $mailbox_cache[$iAccount.'_'.$aMailbox['NAME']] = $aMailbox; |
1744 | sqsession_register($mailbox_cache,'mailbox_cache'); |
a91189d6 |
1745 | } |
73ad81bf |
1746 | sqimap_logout($imap_stream); |
a43e4b90 |
1747 | } |
0c59bbe1 |
1748 | return $success; |
a43e4b90 |
1749 | } |
828c58f1 |
1750 | ?> |