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