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