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