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