Update
[squirrelmail.git] / src / compose.php
CommitLineData
59177427 1<?php
895905c0 2
35586184 3/**
4 * compose.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 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 *
17 * $Id$
18 */
f7fb20fe 19
35586184 20/*****************************************************************/
21/*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
22/*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
23/*** + Base level indent should begin at left margin, as ***/
24/*** the require_once below looks. ***/
25/*** + All identation should consist of four space blocks ***/
26/*** + Tab characters are evil. ***/
27/*** + all comments should use "slash-star ... star-slash" ***/
28/*** style -- no pound characters, no slash-slash style ***/
29/*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
30/*** ALWAYS USE { AND } CHARACTERS!!! ***/
31/*** + Please use ' instead of ", when possible. Note " ***/
32/*** should always be used in _( ) function calls. ***/
33/*** Thank you for your help making the SM code more readable. ***/
34/*****************************************************************/
35
36require_once('../src/validate.php');
37require_once('../functions/imap.php');
38require_once('../functions/date.php');
39require_once('../functions/mime.php');
40require_once('../functions/smtp.php');
41require_once('../functions/display_messages.php');
42require_once('../functions/plugin.php');
8467bf00 43
48985d59 44if (!isset($attachments)) {
45 $attachments = array();
46 session_register('attachments');
47}
48
49/* This function is used when not sending or adding attachments */
50function newMail () {
51 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
52 $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size,
53 $draft_id, $use_signature;
54
55 $send_to = decodeHeader($send_to);
56 $send_to_cc = decodeHeader($send_to_cc);
57 $send_to_bcc = decodeHeader($send_to_bcc);
58
59 if ($forward_id) {
60 $id = $forward_id;
61 } elseif ($reply_id) {
62 $id = $reply_id;
63 }
64
65 if ($draft_id){
66 $id = $draft_id;
67 $use_signature = FALSE;
68 }
69
70 if (isset($id)) {
71 sqimap_mailbox_select($imapConnection, $mailbox);
72 $message = sqimap_get_message($imapConnection, $id, $mailbox);
73 $orig_header = $message->header;
74 if ($ent_num) {
1195c340 75 $message = getEntity($message, $ent_num);
48985d59 76 }
77 if ($message->header->type0 == 'text' ||
78 $message->header->type1 == 'message') {
79 if ($ent_num) {
80 $body = decodeBody(
81 mime_fetch_body($imapConnection, $id, $ent_num),
82 $message->header->encoding);
83 } else {
84 $body = decodeBody(
85 mime_fetch_body($imapConnection, $id, 1),
86 $message->header->encoding);
87 }
88 } else {
429f8906 89 $body = "";
48985d59 90 }
9487c2ff 91
48985d59 92 if ($message->header->type1 == "html") {
429f8906 93 $body = strip_tags($body);
48985d59 94 }
f82d9be2 95
48985d59 96 sqUnWordWrap($body);
97 $body_ary = explode("\n", $body);
98 $i = count($body_ary) - 1;
99 while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) {
fb6ce88e 100 unset($body_ary[$i]);
101 $i --;
48985d59 102 }
103 $body = '';
104 for ($i=0; isset($body_ary[$i]); $i++) {
105 if ($reply_id) {
106 if (ereg('^[ >]+', $body_ary[$i])) {
01aab860 107 $body_ary[$i] = '>' . $body_ary[$i];
48985d59 108 } else {
01aab860 109 $body_ary[$i] = '> ' . $body_ary[$i];
110 }
111 }
a951522b 112 if (!$draft_id) {
113 sqWordWrap($body_ary[$i], $editor_size - 1);
114 }
01aab860 115 $body .= $body_ary[$i] . "\n";
f923b93d 116 unset($body_ary[$i]);
48985d59 117 }
118 if ($forward_id) {
119 $bodyTop = '-------- ' . _("Original Message") . " --------\n" .
120 _("Subject") . ': ' . $orig_header->subject . "\n" .
121 _("From") . ': ' . $orig_header->from . "\n" .
122 _("To") . ': ' . $orig_header->to[0] . "\n";
01aab860 123 if (count($orig_header->to) > 1) {
124 for ($x=1; $x < count($orig_header->to); $x++) {
48985d59 125 $bodyTop .= ' ' . $orig_header->to[$x] . "\n";
01aab860 126 }
127 }
128 $bodyTop .= "\n";
129 $body = $bodyTop . $body;
856af1e0 130 } else if ($reply_id) {
9af31e64 131 $orig_from = decodeHeader($orig_header->from);
248bfebb 132 $body = getReplyCitation($orig_from) . $body;
78509c54 133 }
9487c2ff 134
01aab860 135 return;
48985d59 136 }
429f8906 137
48985d59 138 if (!$send_to) {
29d08a52 139 $send_to = sqimap_find_email($send_to);
48985d59 140 }
29d08a52 141
48985d59 142 /* This formats a CC string if they hit "reply all" */
143 if ($send_to_cc != '') {
144 $send_to_cc = ereg_replace('"[^"]*"', '', $send_to_cc);
145 $send_to_cc = ereg_replace(';', ',', $send_to_cc);
146 $sendcc = explode(',', $send_to_cc);
147 $send_to_cc = '';
9487c2ff 148
48985d59 149 for ($i = 0; $i < count($sendcc); $i++) {
df15de21 150 $sendcc[$i] = trim($sendcc[$i]);
48985d59 151 if ($sendcc[$i] == '') {
152 continue;
153 }
9487c2ff 154
a53e5469 155 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
48985d59 156 $whofrom = sqimap_find_displayable_name($msg['HEADER']['FROM']);
157 $whoreplyto = sqimap_find_email($msg['HEADER']['REPLYTO']);
9487c2ff 158
df15de21 159 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
160 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
48985d59 161 (trim($sendcc[$i]) != '')) {
162 $send_to_cc .= trim($sendcc[$i]) . ', ';
df15de21 163 }
48985d59 164 }
165 $send_to_cc = trim($send_to_cc);
166 if (substr($send_to_cc, -1) == ',') {
df15de21 167 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
48985d59 168 }
169 }
170} /* function newMail() */
171
78509c54 172
48985d59 173function getAttachments($message) {
174 global $mailbox, $attachments, $attachment_dir, $imapConnection,
175 $ent_num, $forward_id, $draft_id, $username;
0a17f9dd 176
48985d59 177 if (isset($draft_id)) {
0a17f9dd 178 $id = $draft_id;
48985d59 179 } else {
0a17f9dd 180 $id = $forward_id;
48985d59 181 }
f972eb46 182
48985d59 183 if (!$message) {
184 sqimap_mailbox_select($imapConnection, $mailbox);
185 $message = sqimap_get_message($imapConnection, $id, $mailbox);
186 }
9487c2ff 187
48985d59 188 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
189 if (count($message->entities) == 0) {
190 if ($message->header->entity_id != $ent_num) {
191 $filename = decodeHeader($message->header->filename);
5100704d 192
48985d59 193 if ($filename == "") {
194 $filename = "untitled-".$message->header->entity_id;
195 }
9487c2ff 196
48985d59 197 $localfilename = GenerateRandomString(32, '', 7);
198 $full_localfilename = "$hashed_attachment_dir/$localfilename";
199 while (file_exists($full_localfilename)) {
200 $localfilename = GenerateRandomString(32, '', 7);
201 $full_localfilename = "$hashed_attachment_dir/$localfilename";
202 }
0a17f9dd 203
48985d59 204 $newAttachment = array();
205 $newAttachment['localfilename'] = $localfilename;
206 $newAttachment['remotefilename'] = $filename;
207 $newAttachment['type'] = strtolower($message->header->type0 .
208 '/' . $message->header->type1);
209
210 /* Write Attachment to file */
211 $fp = fopen ("$hashed_attachment_dir/$localfilename", 'w');
212 fputs($fp, decodeBody(mime_fetch_body($imapConnection,
213 $id, $message->header->entity_id),
214 $message->header->encoding));
215 fclose ($fp);
216
217 $attachments[] = $newAttachment;
218 }
219 } else {
220 for ($i = 0; $i < count($message->entities); $i++) {
221 getAttachments($message->entities[$i]);
222 }
223 }
224 return;
225}
226
227function showInputForm () {
228 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
229 $passed_body, $color, $use_signature, $signature, $prefix_sig,
230 $editor_size, $attachments, $subject, $newmail,
231 $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
232 $from_htmladdr_search, $location_of_buttons, $attachment_dir,
233 $username, $data_dir, $identity, $draft_id, $delete_draft,
234 $mailprio;
235
236 $subject = decodeHeader($subject);
237 $reply_subj = decodeHeader($reply_subj);
238 $forward_subj = decodeHeader($forward_subj);
239
240 if ($use_javascript_addr_book) {
241 echo "\n". '<SCRIPT LANGUAGE=JavaScript><!--' . "\n" .
242 'function open_abook() { ' . "\n" .
243 ' var nwin = window.open("addrbook_popup.php","abookpopup",' .
244 '"width=670,height=300,resizable=yes,scrollbars=yes");' . "\n" .
245 ' if((!nwin.opener) && (document.windows != null))' . "\n" .
246 ' nwin.opener = document.windows;' . "\n" .
247 "}\n" .
248 '// --></SCRIPT>' . "\n\n";
249 }
250
251 echo "\n" . '<FORM name=compose action="compose.php" METHOD=POST ' .
252 'ENCTYPE="multipart/form-data"';
253 do_hook("compose_form");
254 echo ">\n";
255
256 if (isset($draft_id)) {
257 echo '<input type="hidden" name="delete_draft" value="' . $draft_id . "\">\n";
258 }
259 if (isset($delete_draft)) {
260 echo '<input type="hidden" name="delete_draft" value="' . $delete_draft. "\">\n";
261 }
262
263 echo '<TABLE WIDTH="100%" ALIGN=center CELLSPACING=0 BORDER=0>' . "\n";
264
265 if ($location_of_buttons == 'top') { showComposeButtonRow(); }
266
267 $idents = getPref($data_dir, $username, 'identities');
268 if ($idents != '' && $idents > 1) {
269 echo ' <TR>' . "\n" .
270 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' .
271 "\n" .
272 _("From:") .
273 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
274 '<select name=identity>' . "\n" .
275 '<option value=default>' .
276 htmlspecialchars(getPref($data_dir, $username, 'full_name'));
277 $em = getPref($data_dir, $username, 'email_address');
278 if ($em != '') {
248bfebb 279 echo htmlspecialchars(' <' . $em . '>') . "\n";
48985d59 280 }
281 for ($i = 1; $i < $idents; $i ++) {
248bfebb 282 echo '<option value="' . $i . '"';
48985d59 283 if (isset($identity) && $identity == $i) {
248bfebb 284 echo ' SELECTED';
48985d59 285 }
286 echo '>' . htmlspecialchars(getPref($data_dir, $username,
287 'full_name' . $i));
248bfebb 288 $em = getPref($data_dir, $username, 'email_address' . $i);
48985d59 289 if ($em != '') {
248bfebb 290 echo htmlspecialchars(' <' . $em . '>') . "\n";
48985d59 291 }
292 }
293 echo '</select>' . "\n" .
294 ' </TD>' . "\n" .
295 ' </TR>' . "\n";
296 }
297 echo ' <TR>' . "\n" .
298 ' <TD BGCOLOR="' . $color[4] . '" WIDTH="10%" ALIGN=RIGHT>' . "\n" .
299 _("To:") .
300 ' </TD><TD BGCOLOR="' . $color[4] . '" WIDTH="90%">' . "\n" .
301 ' <INPUT TYPE=text NAME="send_to" VALUE="' .
302 htmlspecialchars($send_to) . '" SIZE=60><BR>' . "\n" .
303 ' </TD>' . "\n" .
304 ' </TR>' . "\n" .
305 ' <TR>' . "\n" .
306 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
307 _("CC:") .
308 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
309 ' <INPUT TYPE=text NAME="send_to_cc" SIZE=60 VALUE="' .
310 htmlspecialchars($send_to_cc) . '"><BR>' . "\n" .
311 ' </TD>' . "\n" .
312 ' </TR>' . "\n" .
313 ' <TR>' . "\n" .
314 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
315 _("BCC:") .
316 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n" .
317 ' <INPUT TYPE=text NAME="send_to_bcc" VALUE="' .
318 htmlspecialchars($send_to_bcc) . '" SIZE=60><BR>' . "\n" .
319 '</TD></TR>' . "\n" .
320 ' <TR>' . "\n" .
321 ' <TD BGCOLOR="' . $color[4] . '" ALIGN=RIGHT>' . "\n" .
322 _("Subject:") .
323 ' </TD><TD BGCOLOR="' . $color[4] . '" ALIGN=LEFT>' . "\n";
324 if ($reply_subj) {
325 $reply_subj = str_replace('"', "'", $reply_subj);
326 $reply_subj = trim($reply_subj);
327 if (substr(strtolower($reply_subj), 0, 3) != 're:')
328 $reply_subj = 'Re: ' . $reply_subj;
329 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
330 htmlspecialchars($reply_subj) . '">';
331 } else if ($forward_subj) {
332 $forward_subj = trim($forward_subj);
333 if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') &&
334 (substr(strtolower($forward_subj), 0, 5) != '[fwd:') &&
335 (substr(strtolower($forward_subj), 0, 6) != '[ fwd:')) {
336 $forward_subj = '[Fwd: ' . $forward_subj . ']';
337 }
338 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
339 htmlspecialchars($forward_subj) . '">';
340 } else {
341 echo ' <INPUT TYPE=text NAME=subject SIZE=60 VALUE="' .
342 htmlspecialchars($subject) . '">';
343 }
344 echo '</td></tr>' . "\n\n";
345
346 if ($location_of_buttons == 'between') { showComposeButtonRow(); }
347
348 echo ' <TR>' . "\n" .
349 ' <TD BGCOLOR="' . $color[4] . '" COLSPAN=2>' . "\n" .
350 ' &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS="' .
351 $editor_size . '" WRAP=HARD>' . htmlspecialchars($body);
352 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
353 if ( $prefix_sig == true ) {
354 echo "\n\n-- \n" . htmlspecialchars($signature);
355 } else {
356 echo "\n\n" . htmlspecialchars($signature);
357 }
358 }
359 echo '</TEXTAREA><BR>' . "\n" .
360 ' </TD>' . "\n" .
361 ' </TR>' . "\n";
362
363 if ($location_of_buttons == 'bottom') {
364 showComposeButtonRow();
365 } else {
366 echo ' <TR><TD>&nbsp;</TD><TD ALIGN=LEFT><INPUT TYPE=SUBMIT ' .
367 'NAME=send VALUE="' . _("Send") . '"></TD></TR>' . "\n";
368 }
369
370 /* This code is for attachments */
371 echo ' <TR>' . "\n" .
372 ' <TD VALIGN=MIDDLE ALIGN=RIGHT>' . "\n" .
373 _("Attach:") .
374 ' </TD>' . "\n" .
375 ' <TD VALIGN=MIDDLE ALIGN=LEFT>' . "\n" .
376 ' <INPUT NAME="attachfile" SIZE=48 TYPE="file">' . "\n" .
377 ' &nbsp;&nbsp;<input type="submit" name="attach"' .
378 ' value="' . _("Add") .'">' . "\n" .
379 ' </TD>' . "\n" .
380 ' </TR>' . "\n";
381 if (count($attachments)) {
382 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
383 echo '<tr><td bgcolor="' . $color[0] . '" align=right>' . "\n" .
384 '&nbsp;' .
385 '</td><td align=left bgcolor="' . $color[0] . '">';
386 foreach ($attachments as $key => $info) {
3392dc86 387 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
48985d59 388 echo '<input type="checkbox" name="delete[]" value="' . $key . "\">\n" .
389 $info['remotefilename'] . ' - ' . $info['type'] . ' (' .
390 show_readable_size(filesize($attached_file)) . ")<br>\n";
391 }
392
393 echo '<input type="submit" name="do_delete" value="' .
394 _("Delete selected attachments") . "\">\n" .
395 '</td></tr>';
396 }
397 /* End of attachment code */
398
399 echo '</TABLE>' . "\n";
400 if ($reply_id) {
401 echo '<input type=hidden name=reply_id value=' . $reply_id . ">\n";
402 }
403 echo '<INPUT TYPE=hidden NAME=mailbox VALUE="' . htmlspecialchars($mailbox) .
404 "\">\n" .
405 '</FORM>';
406 do_hook("compose_bottom");
407 echo '</BODY></HTML>' . "\n";
408}
409
410
411
412
9487c2ff 413
4ba45d11 414
9487c2ff 415
441f2d33 416 function showComposeButtonRow() {
020abcf3 417 global $use_javascript_addr_book, $save_as_draft,
418 $default_use_priority, $mailprio;
9487c2ff 419
441f2d33 420 echo " <TR><td>\n </td><td>\n";
421 if ($use_javascript_addr_book) {
422 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"";
423 echo " <input type=button value=\\\""._("Addresses")."\\\" onclick='javascript:open_abook();'>\");";
424 echo " // --></SCRIPT><NOSCRIPT>\n";
425 echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
426 echo " </NOSCRIPT>\n";
9487c2ff 427 } else {
441f2d33 428 echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
9487c2ff 429 }
441f2d33 430 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
9487c2ff 431
f7b1b3b1 432 if ($save_as_draft) {
57155fe3 433 echo '<input type="submit" name ="draft" value="' . _("Save Draft") . "\">\n";
f7b1b3b1 434 }
020abcf3 435 if ($default_use_priority) {
436 if(!isset($mailprio)) {
437 $mailprio = "3";
438 }
439 echo "\n\t". _("Priority") .":<select name=\"mailprio\">".
440 "\n\t\t<option value=1".($mailprio=="1"?" selected":"").">". _("High") ."</option>".
441 "\n\t\t<option value=3".($mailprio=="3"?" selected":"").">". _("Normal") ."</option>".
442 "\n\t\t<option value=5".($mailprio=="5"?" selected":"").">". _("Low")."</option>".
443 "\n\t</select>";
444 }
0a17f9dd 445
441f2d33 446 do_hook("compose_button_row");
447
448 echo " </TD>\n";
449 echo " </TR>\n\n";
450 }
8467bf00 451
0ad7dbda 452 function checkInput ($show) {
453 /** I implemented the $show variable because the error messages
454 were getting sent before the page header. So, I check once
455 using $show=false, and then when i'm ready to display the
456 error message, show=true **/
457 global $body, $send_to, $subject, $color;
b278172f 458
99fa2b21 459 if ($send_to == "") {
0ad7dbda 460 if ($show)
461 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
df15de21 462 return false;
b278172f 463 }
df15de21 464 return true;
465 } // function checkInput()
466
3806fa52 467
056ddad7 468 // True if FAILURE
469 function saveAttachedFiles() {
3392dc86 470 global $HTTP_POST_FILES, $attachment_dir, $attachments, $username;
020abcf3 471
3392dc86 472 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
056ddad7 473 $localfilename = GenerateRandomString(32, '', 7);
3392dc86 474 $full_localfilename = "$hashed_attachment_dir/$localfilename";
475 while (file_exists($full_localfilename)) {
a4fe5de0 476 $localfilename = GenerateRandomString(32, '', 7);
3392dc86 477 $full_localfilename = "$hashed_attachment_dir/$localfilename";
478 }
f972eb46 479
3392dc86 480 if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
481 if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $full_localfilename)) {
056ddad7 482 return true;
483 }
484 }
9487c2ff 485
f972eb46 486 $newAttachment['localfilename'] = $localfilename;
487 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
9487c2ff 488 $newAttachment['type'] =
f972eb46 489 strtolower($HTTP_POST_FILES['attachfile']['type']);
8ef72f33 490
491 if ($newAttachment['type'] == "")
492 $newAttachment['type'] = 'application/octet-stream';
493
f972eb46 494 $attachments[] = $newAttachment;
056ddad7 495 }
9487c2ff 496
2d367c68 497 if (!isset($mailbox) || $mailbox == '' || ($mailbox == 'None'))
dcb7f454 498 $mailbox = "INBOX";
3806fa52 499
0a17f9dd 500 if (isset($draft)) {
501 require_once ('../src/draft_actions.php');
f7b1b3b1 502 if (!saveMessageAsDraft($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id)) {
0a17f9dd 503 showInputForm();
504 exit();
505 } else {
f7b1b3b1 506 $draft_message = _("Draft Email Saved");
45c4e0f2 507 /* If this is a resumed draft, then delete the original */
508 if(isset($delete_draft)) {
509 Header("Location: delete_message.php?mailbox=$draft_folder&message=$delete_draft&sort=$sort&startMessage=1");
510 exit();
511 } else {
512 Header("Location: right_main.php?mailbox=$draft_folder&sort=$sort&startMessage=1&note=$draft_message");
513 exit();
514 }
0a17f9dd 515 }
516 }
517
f972eb46 518 if (isset($send)) {
245a6892 519 if (isset($HTTP_POST_FILES['attachfile']) &&
520 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
78b4216e 521 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none')
056ddad7 522 $AttachFailure = saveAttachedFiles();
a7ea7540 523 if (checkInput(false) && !isset($AttachFailure)) {
35d520d3 524 $urlMailbox = urlencode (trim($mailbox));
525 if (! isset($reply_id))
526 $reply_id = 0;
ebab5342 527 // Set $default_charset to correspond with the user's selection
f923b93d 528 // of language interface.
529 set_my_charset();
eedcdd97 530
531 // This is to change all newlines to \n
248bfebb 532 // We'll change them to \r\n later (in the sendMessage function)
533 $body = str_replace("\r\n", "\n", $body);
534 $body = str_replace("\r", "\n", $body);
9487c2ff 535
248bfebb 536 // Rewrap $body so that no line is bigger than $editor_size
537 // This should only really kick in the sqWordWrap function
538 // if the browser doesn't support "HARD" as the wrap type
539 // Or, in Opera's case, something goes wrong.
540 $body = explode("\n", $body);
541 $newBody = '';
542 foreach ($body as $line) {
543 if( $line <> '-- ' )
544 $line = rtrim($line);
545 if (strlen($line) <= $editor_size + 1)
546 $newBody .= $line . "\n";
547 else {
548 sqWordWrap($line, $editor_size) . "\n";
549 $newBody .= $line;
550 }
551 }
552 $body = $newBody;
9487c2ff 553
f923b93d 554 do_hook("compose_send");
9487c2ff 555
872c4fac 556 if (! isset($mailprio))
557 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
9bc3dc44 558 $subject, $body, $reply_id);
872c4fac 559 else
9bc3dc44 560 $Result = sendMessage($send_to, $send_to_cc, $send_to_bcc,
561 $subject, $body, $reply_id, $mailprio);
872c4fac 562 if (! $Result) {
9487c2ff 563 showInputForm();
248bfebb 564 exit();
565 }
0a17f9dd 566 if ( isset($delete_draft)) {
cc82b756 567 Header("Location: delete_message.php?mailbox=$draft_folder&message=$delete_draft&sort=$sort&startMessage=1");
0a17f9dd 568 exit();
569 }
570
248bfebb 571 Header("Location: right_main.php?mailbox=$urlMailbox&sort=$sort&startMessage=1");
df15de21 572 } else {
01aab860 573 //$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
dcb7f454 574 displayPageHeader($color, $mailbox);
9487c2ff 575
7a813c24 576 if (isset($AttachFailure))
056ddad7 577 plain_error_message(_("Could not move/copy file. File not attached"), $color);
578
0ad7dbda 579 checkInput(true);
9487c2ff 580
df15de21 581 showInputForm();
01aab860 582 //sqimap_logout($imapConnection);
7c6cb7ca 583 }
245a6892 584 } else if (isset($html_addr_search_done)) {
dcb7f454 585 displayPageHeader($color, $mailbox);
3806fa52 586
b8796881 587 if (isset($send_to_search) && is_array($send_to_search)) {
588 foreach ($send_to_search as $k => $v) {
248bfebb 589 if (substr($k, 0, 1) == 'T') {
b8796881 590 if ($send_to)
591 $send_to .= ', ';
592 $send_to .= $v;
248bfebb 593 }
594 elseif (substr($k, 0, 1) == 'C') {
595 if ($send_to_cc)
596 $send_to_cc .= ', ';
597 $send_to_cc .= $v;
598 }
599 elseif (substr($k, 0, 1) == 'B') {
600 if ($send_to_bcc)
601 $send_to_bcc .= ', ';
602 $send_to_bcc .= $v;
603 }
e53f7484 604 }
a98bed68 605 }
9487c2ff 606
3806fa52 607 showInputForm();
245a6892 608 } else if (isset($html_addr_search)) {
f17728d1 609 if (isset($HTTP_POST_FILES['attachfile']) &&
610 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
611 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none')
612 {
613 if (saveAttachedFiles())
614 plain_error_message(_("Could not move/copy file. File not attached"), $color);
615 }
591d2a88 616 // I am using an include so as to elminiate an extra unnecessary click. If you
617 // can think of a better way, please implement it.
ff8a98e7 618 include_once('./addrbook_search_html.php');
4ba45d11 619 } else if (isset($attach)) {
056ddad7 620 if (saveAttachedFiles())
22ef7536 621 plain_error_message(_("Could not move/copy file. File not attached"), $color);
21bc0570 622 displayPageHeader($color, $mailbox);
4ba45d11 623 showInputForm();
624 } else if (isset($do_delete)) {
dcb7f454 625 displayPageHeader($color, $mailbox);
fc3348ac 626
3392dc86 627 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
628 if (isset($delete) && is_array($delete)) {
629 foreach($delete as $index) {
630 $attached_file = $hashed_attachment_dir . '/'
631 . $attachments[$index]['localfilename'];
632 unlink ($attached_file);
f972eb46 633 unset ($attachments[$index]);
f923b93d 634 }
4ba45d11 635 }
4bfed9f3 636
4ba45d11 637 showInputForm();
638 } else {
991a059e 639 // This handles the default case as well as the error case
640 // (they had the same code) --> if (isset($smtpErrors))
9487c2ff 641 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
991a059e 642 $imapPort, 0);
dcb7f454 643 displayPageHeader($color, $mailbox);
fc3348ac 644
b57c4e63 645 $newmail = true;
f972eb46 646
647 ClearAttachments();
648
991a059e 649 if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num)
650 getAttachments(0);
9487c2ff 651
0a17f9dd 652 if (isset($draft_id) && $draft_id && isset($ent_num) && $ent_num)
653 getAttachments(0);
654
1220e677 655 newMail();
4ba45d11 656 showInputForm();
1195c340 657 sqimap_logout($imapConnection);
4ba45d11 658 }
9487c2ff 659
f923b93d 660 function ClearAttachments() {
3392dc86 661 global $username, $attachments, $attachment_dir;
662 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
9487c2ff 663
f923b93d 664 foreach ($attachments as $info) {
3392dc86 665 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
666 if (file_exists($attached_file)) {
667 unlink($attached_file);
f923b93d 668 }
f972eb46 669 }
9487c2ff 670
f972eb46 671 $attachments = array();
672 }
cd41fc8d 673
674 function getReplyCitation($orig_from) {
675 global $reply_citation_style, $reply_citation_start, $reply_citation_end;
676
677 /* First, return an empty string when no citation style selected. */
678 if (($reply_citation_style == '') || ($reply_citation_style == 'none')) {
679 return ('');
680 }
681
1c252cc3 682 /* Decode the users name. */
683 $parpos = strpos($orig_from, '(');
684 if ($parpos === false) {
685 $orig_from = trim(substr($orig_from, 0, strpos($orig_from, '<')));
686 $orig_from = str_replace('"', '', $orig_from);
687 $orig_from = str_replace("'", '', $orig_from);
688 } else {
689 $end_parpos = strrpos($orig_from, ')');
690 $end_parpos -= ($end_parpos === false ? $end_parpos : $parpos + 1);
691 $orig_from = trim(substr($orig_from, $parpos + 1, $end_parpos));
692 }
693
694 /* Make sure our final value isn't an empty string. */
695 if ($orig_from == '') {
696 return ('');
697 }
698
cd41fc8d 699 /* Otherwise, try to select the desired citation style. */
700 switch ($reply_citation_style) {
701 case 'author_said':
702 $start = '';
703 $end = ' ' . _("said") . ':';
704 break;
705 case 'quote_who':
706 $start = '<' . _("quote") . ' ' . _("who") . '="';
707 $end = '">';
708 break;
709 case 'user-defined':
710 $start = $reply_citation_start;
711 $end = $reply_citation_end;
712 break;
713 default: return ('');
714 }
715
716 /* Build and return the citation string. */
717 return ($start . $orig_from . $end . "\n");
9487c2ff 718 }
0a17f9dd 719?>