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