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