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