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