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