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