* Shows the attached file's type and size
[squirrelmail.git] / src / compose.php
CommitLineData
59177427 1<?php
ef870322 2 /**
3 ** compose.php
4 **
5 ** Copyright (c) 1999-2000 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** This code sends a mail.
df15de21 9 **
10 ** There are 3 modes of operation:
11 ** - Start new mail
12 ** - Add an attachment
13 ** - Send mail
245a6892 14 **
15 ** $Id$
df15de21 16 **/
d51894be 17
2a32fc83 18 session_start();
19
d068c0ec 20 if (!isset($strings_php))
21 include("../functions/strings.php");
245a6892 22 if (!isset($config_php))
23 include("../config/config.php");
d068c0ec 24 if (!isset($page_header_php))
25 include("../functions/page_header.php");
26 if (!isset($imap_php))
27 include("../functions/imap.php");
28 if (!isset($date_php))
29 include("../functions/date.php");
30 if (!isset($mime_php))
31 include("../functions/mime.php");
32 if (!isset($smtp_php))
33 include("../functions/smtp.php");
34 if (!isset($display_messages_php))
35 include("../functions/display_messages.php");
3c13b9fb 36 if (!isset($auth_php))
37 include ("../functions/auth.php");
15bfc1bc 38 if (!isset($plugin_php))
39 include ("../functions/plugin.php");
f7fb20fe 40
d3cdb279 41 include("../src/load_prefs.php");
8467bf00 42
79be8a0b 43 if (!isset($attachments))
f972eb46 44 {
79be8a0b 45 $attachments = array();
f972eb46 46 session_register('attachments');
47 }
a98bed68 48
d7981cd8 49
4ba45d11 50 // This function is used when not sending or adding attachments
df15de21 51 function newMail () {
52 global $forward_id, $imapConnection, $msg, $ent_num, $body_ary, $body,
a794e82c 53 $reply_id, $send_to, $send_to_cc, $mailbox, $send_to_bcc, $editor_size;
e39d73e5 54
d51894be 55 $send_to = decodeHeader($send_to);
56 $send_to_cc = decodeHeader($send_to_cc);
57 $send_to_bcc = decodeHeader($send_to_bcc);
a53e5469 58
429f8906 59 if ($forward_id)
60 $id = $forward_id;
3b5b889f 61 elseif ($reply_id)
429f8906 62 $id = $reply_id;
63
1195c340 64
245a6892 65 if (isset($id)) {
813eba2f 66 sqimap_mailbox_select($imapConnection, $mailbox);
429f8906 67 $message = sqimap_get_message($imapConnection, $id, $mailbox);
8d8ab69a 68 $orig_header = $message->header;
1195c340 69 if ($ent_num)
70 $message = getEntity($message, $ent_num);
429f8906 71
72 if ($message->header->type0 == "text" || $message->header->type1 == "message") {
1195c340 73 if ($ent_num)
74 $body = decodeBody(mime_fetch_body($imapConnection, $id, $ent_num), $message->header->encoding);
75 else
76 $body = decodeBody(mime_fetch_body($imapConnection, $id, 1), $message->header->encoding);
429f8906 77 } else {
78 $body = "";
df15de21 79 }
3bc5ef2d 80
429f8906 81 if ($message->header->type1 == "html")
82 $body = strip_tags($body);
f82d9be2 83
01aab860 84 sqUnWordWrap($body);
a794e82c 85 $body_ary = explode("\n", $body);
fb6ce88e 86 $i = count($body_ary) - 1;
3bc5ef2d 87 while ($i >= 0 && ereg("^[>\\s]*$", $body_ary[$i])) {
fb6ce88e 88 unset($body_ary[$i]);
89 $i --;
441f2d33 90 }
a794e82c 91 $body = "";
3bc5ef2d 92 for ($i=0; isset($body_ary[$i]); $i++) {
01aab860 93 if (! $forward_id)
94 {
f82d9be2 95 if (ereg('^[\\s>]+', $body_ary[$i]))
01aab860 96 {
97 $body_ary[$i] = '>' . $body_ary[$i];
98 }
99 else
100 {
101 $body_ary[$i] = '> ' . $body_ary[$i];
102 }
103 }
a794e82c 104 sqWordWrap($body_ary[$i], $editor_size - 1);
01aab860 105 $body .= $body_ary[$i] . "\n";
f82d9be2 106 unset($body_ary[$i]);
a794e82c 107 }
01aab860 108 if ($forward_id)
109 {
110 $bodyTop = "-------- " . _("Original Message") . " --------\n";
111 $bodyTop .= _("Subject") . ": " . $orig_header->subject . "\n";
112 $bodyTop .= _("From") . ": " . $orig_header->from . "\n";
113 $bodyTop .= _("To") . ": " . $orig_header->to[0] . "\n";
114 if (count($orig_header->to) > 1) {
115 for ($x=1; $x < count($orig_header->to); $x++) {
116 $bodyTop .= " " . $orig_header->to[$x] . "\n";
117 }
118 }
119 $bodyTop .= "\n";
120 $body = $bodyTop . $body;
78509c54 121 }
441f2d33 122
01aab860 123 return;
78509c54 124 }
429f8906 125
29d08a52 126 if (!$send_to) {
127 $send_to = sqimap_find_email($send_to);
128 }
129
df15de21 130 /** This formats a CC string if they hit "reply all" **/
131 if ($send_to_cc != "") {
a48fbf9b 132 $send_to_cc = ereg_replace( '"[^"]*"', "", $send_to_cc);
df15de21 133 $send_to_cc = ereg_replace(";", ",", $send_to_cc);
134 $sendcc = explode(",", $send_to_cc);
135 $send_to_cc = "";
136
137 for ($i = 0; $i < count($sendcc); $i++) {
138 $sendcc[$i] = trim($sendcc[$i]);
139 if ($sendcc[$i] == "")
140 continue;
141
a53e5469 142 $sendcc[$i] = sqimap_find_email($sendcc[$i]);
813eba2f 143 $whofrom = sqimap_find_displayable_name($msg["HEADER"]["FROM"]);
144 $whoreplyto = sqimap_find_email($msg["HEADER"]["REPLYTO"]);
df15de21 145
146 if ((strtolower(trim($sendcc[$i])) != strtolower(trim($whofrom))) &&
147 (strtolower(trim($sendcc[$i])) != strtolower(trim($whoreplyto))) &&
148 (trim($sendcc[$i]) != "")) {
149 $send_to_cc .= trim($sendcc[$i]) . ", ";
150 }
151 }
152 $send_to_cc = trim($send_to_cc);
153 if (substr($send_to_cc, -1) == ",") {
154 $send_to_cc = substr($send_to_cc, 0, strlen($send_to_cc) - 1);
155 }
156 }
157 } // function newMail()
78509c54 158
5713b4f9 159 function getAttachments($message) {
160 global $mailbox, $attachments, $attachment_dir, $imapConnection,
161 $ent_num, $forward_id;
f972eb46 162
5713b4f9 163 if (!$message) {
164 sqimap_mailbox_select($imapConnection, $mailbox);
991a059e 165 $message = sqimap_get_message($imapConnection, $forward_id,
166 $mailbox);
167 }
5713b4f9 168
991a059e 169 if (count($message->entities) == 0) {
170 if ($message->header->entity_id != $ent_num) {
171 $filename = decodeHeader($message->header->filename);
5713b4f9 172
991a059e 173 if ($filename == "")
174 $filename = "untitled-".$message->header->entity_id;
5713b4f9 175
991a059e 176 $localfilename = GenerateRandomString(32, '', 7);
f972eb46 177 while (file_exists($attachment_dir . $localfilename))
511f7816 178 $localfilename = GenerateRandomString(32, '', 7);
f972eb46 179
180 $newAttachment['localfilename'] = $localfilename;
181 $newAttachment['remotefilename'] = $filename;
d7981cd8 182 $newAttachment['type'] = strtolower($message->header->type0 .
f972eb46 183 '/' . $message->header->type1);
991a059e 184
185 // Write Attachment to file
f972eb46 186 $fp = fopen ($attachment_dir.$localfilename, 'w');
991a059e 187 fputs ($fp, decodeBody(mime_fetch_body($imapConnection,
188 $forward_id, $message->header->entity_id),
189 $message->header->encoding));
190 fclose ($fp);
5713b4f9 191
f972eb46 192 $attachments[] = $newAttachment;
991a059e 193 }
5713b4f9 194 } else {
991a059e 195 for ($i = 0; $i < count($message->entities); $i++) {
5713b4f9 196 getAttachments($message->entities[$i]);
991a059e 197 }
5713b4f9 198 }
199 return;
991a059e 200 }
5713b4f9 201
df15de21 202 function showInputForm () {
203 global $send_to, $send_to_cc, $reply_subj, $forward_subj, $body,
b8163cc4 204 $passed_body, $color, $use_signature, $signature, $prefix_sig,
205 $editor_size, $attachments, $subject, $newmail,
206 $use_javascript_addr_book, $send_to_bcc, $reply_id, $mailbox,
ffefe1e2 207 $from_htmladdr_search, $location_of_buttons, $attachment_dir;
78509c54 208
d51894be 209 $subject = decodeHeader($subject);
2e434774 210 $reply_subj = decodeHeader($reply_subj);
211 $forward_subj = decodeHeader($forward_subj);
01aab860 212
3806fa52 213 if ($use_javascript_addr_book) {
214 echo "\n<SCRIPT LANGUAGE=JavaScript><!--\n";
215 echo "function open_abook() { \n";
216 echo " var nwin = window.open(\"addrbook_popup.php\",\"abookpopup\",";
217 echo "\"width=670,height=300,resizable=yes,scrollbars=yes\");\n";
218 echo " if((!nwin.opener) && (document.windows != null))\n";
219 echo " nwin.opener = document.windows;\n";
220 echo "}\n";
221 echo "// --></SCRIPT>\n\n";
222 }
5100704d 223
b3911477 224 echo "\n<FORM name=compose action=\"compose.php\" METHOD=POST ENCTYPE=\"multipart/form-data\"";
225 do_hook("compose_form");
226 echo ">\n";
966286ae 227 if ($reply_id) {
228 echo "<input type=hidden name=reply_id value=$reply_id>\n";
6e79bfe2 229 }
cf8758c7 230 printf("<INPUT TYPE=hidden NAME=mailbox VALUE=\"%s\">\n", htmlspecialchars($mailbox));
c5d828b3 231 echo "<TABLE WIDTH=\"100%\" ALIGN=center CELLSPACING=0 BORDER=0>\n";
441f2d33 232
233 if ($location_of_buttons == 'top') showComposeButtonRow();
234
df15de21 235 echo " <TR>\n";
c5d828b3 236 echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
df15de21 237 echo _("To:");
c5d828b3 238 echo " </TD><TD BGCOLOR=\"$color[4]\">\n";
cf8758c7 239 printf(" <INPUT TYPE=text NAME=\"send_to\" VALUE=\"%s\" SIZE=60><BR>\n",
6e79bfe2 240 htmlspecialchars($send_to));
df15de21 241 echo " </TD>\n";
242 echo " </TR>\n";
243 echo " <TR>\n";
c5d828b3 244 echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
aae41ae9 245 echo _("CC:");
c5d828b3 246 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
cf8758c7 247 printf(" <INPUT TYPE=text NAME=\"send_to_cc\" SIZE=60 VALUE=\"%s\"><BR>\n",
6e79bfe2 248 htmlspecialchars($send_to_cc));
df15de21 249 echo " </TD>\n";
250 echo " </TR>\n";
251 echo " <TR>\n";
c5d828b3 252 echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
aae41ae9 253 echo _("BCC:");
761d149e 254 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
cf8758c7 255 printf(" <INPUT TYPE=text NAME=\"send_to_bcc\" VALUE=\"%s\" SIZE=60><BR>\n",
6e79bfe2 256 htmlspecialchars($send_to_bcc));
3806fa52 257 echo "</TD></TR>\n";
5100704d 258
df15de21 259 echo " <TR>\n";
c5d828b3 260 echo " <TD BGCOLOR=\"$color[4]\" ALIGN=RIGHT>\n";
df15de21 261 echo _("Subject:");
761d149e 262 echo " </TD><TD BGCOLOR=\"$color[4]\" ALIGN=LEFT>\n";
df15de21 263 if ($reply_subj) {
264 $reply_subj = str_replace("\"", "'", $reply_subj);
df15de21 265 $reply_subj = trim($reply_subj);
266 if (substr(strtolower($reply_subj), 0, 3) != "re:")
267 $reply_subj = "Re: $reply_subj";
cf8758c7 268 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
6e79bfe2 269 htmlspecialchars($reply_subj));
df15de21 270 } else if ($forward_subj) {
df15de21 271 $forward_subj = trim($forward_subj);
f972eb46 272 if ((substr(strtolower($forward_subj), 0, 4) != 'fwd:') &&
273 (substr(strtolower($forward_subj), 0, 5) != '[fwd:') &&
274 (substr(strtolower($forward_subj), 0, 6) != '[ fwd:'))
df15de21 275 $forward_subj = "[Fwd: $forward_subj]";
cf8758c7 276 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
6e79bfe2 277 htmlspecialchars($forward_subj));
df15de21 278 } else {
6e79bfe2 279 printf(" <INPUT TYPE=text NAME=subject SIZE=60 VALUE=\"%s\">",
280 htmlspecialchars($subject));
31f3d7c0 281 }
480feea7 282 echo "</td></tr>\n\n";
283
441f2d33 284 if ($location_of_buttons == 'between') showComposeButtonRow();
4ba45d11 285
e5b23ff2 286 echo " <TR>\n";
c5d828b3 287 echo " <TD BGCOLOR=\"$color[4]\" COLSPAN=2>\n";
cf8758c7 288 echo " &nbsp;&nbsp;<TEXTAREA NAME=body ROWS=20 COLS=\"$editor_size\" WRAP=HARD>";
441f2d33 289 echo htmlspecialchars($body);
6e79bfe2 290 if ($use_signature == true && $newmail == true && !isset($from_htmladdr_search)) {
b8163cc4 291 if ( $prefix_sig == true )
292 echo "\n\n-- \n" . htmlspecialchars($signature);
293 else
294 echo "\n\n" . htmlspecialchars($signature);
cf8758c7 295 }
296 echo "</TEXTAREA><BR>\n";
e5b23ff2 297 echo " </TD>\n";
298 echo " </TR>\n";
441f2d33 299
300 if ($location_of_buttons == 'bottom')
301 showComposeButtonRow();
302 else {
303 echo " <TR><TD>&nbsp;</TD><TD ALIGN=LEFT><INPUT TYPE=SUBMIT NAME=send VALUE=\""._("Send")."\"></TD></TR>\n";
304 }
e5b23ff2 305
4ba45d11 306 // This code is for attachments
a98bed68 307 echo " <tr>\n";
308 echo " <TD BGCOLOR=\"$color[0]\" VALIGN=TOP ALIGN=RIGHT>\n";
309 echo " <SMALL><BR></SMALL>"._("Attach:");
310 echo " </td><td ALIGN=left BGCOLOR=\"$color[0]\">\n";
944eb785 311 echo " <INPUT NAME=\"attachfile\" SIZE=48 TYPE=\"file\">\n";
95de6c91 312 echo " &nbsp;&nbsp;<input type=\"submit\" name=\"attach\"";
313 echo " value=\"" . _("Add") ."\">\n";
469eb37b 314 echo " </td>\n";
469eb37b 315 echo " </tr>\n";
f972eb46 316 if (count($attachments))
317 {
a98bed68 318 echo "<tr><td bgcolor=\"$color[0]\" align=right>\n";
e5b23ff2 319 echo "&nbsp;";
a98bed68 320 echo "</td><td align=left bgcolor=\"$color[0]\">";
f972eb46 321 foreach ($attachments as $key => $info) {
322 echo "<input type=\"checkbox\" name=\"delete[]\" value=\"$key\">\n";
ffefe1e2 323 echo $info['remotefilename'] . " - " . $info['type'] . " (";
324 echo show_readable_size(filesize($attachment_dir .
325 $info['localfilename'])) . ")<br>\n";
4ba45d11 326 }
327
328 echo "<input type=\"submit\" name=\"do_delete\" value=\""._("Delete selected attachments")."\">\n";
469eb37b 329 echo "</td></tr>";
4ba45d11 330 }
4ba45d11 331 // End of attachment code
332
ffc2ccbc 333 echo "</TABLE>\n";
df15de21 334 echo "</FORM>";
d7d3c4d4 335 do_hook("compose_bottom");
31f3d7c0 336 }
441f2d33 337
338 function showComposeButtonRow() {
2037f4f3 339 global $use_javascript_addr_book;
f972eb46 340
441f2d33 341 echo " <TR><td>\n </td><td>\n";
342 if ($use_javascript_addr_book) {
343 echo " <SCRIPT LANGUAGE=JavaScript><!--\n document.write(\"";
344 echo " <input type=button value=\\\""._("Addresses")."\\\" onclick='javascript:open_abook();'>\");";
345 echo " // --></SCRIPT><NOSCRIPT>\n";
346 echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
347 echo " </NOSCRIPT>\n";
348 } else {
349 echo " <input type=submit name=\"html_addr_search\" value=\""._("Addresses")."\">";
350 }
351 echo "\n <INPUT TYPE=SUBMIT NAME=send VALUE=\"". _("Send") . "\">\n";
352
353 do_hook("compose_button_row");
354
355 echo " </TD>\n";
356 echo " </TR>\n\n";
357 }
8467bf00 358
0ad7dbda 359 function checkInput ($show) {
360 /** I implemented the $show variable because the error messages
361 were getting sent before the page header. So, I check once
362 using $show=false, and then when i'm ready to display the
363 error message, show=true **/
364 global $body, $send_to, $subject, $color;
b278172f 365
99fa2b21 366 if ($send_to == "") {
0ad7dbda 367 if ($show)
368 plain_error_message(_("You have not filled in the \"To:\" field."), $color);
df15de21 369 return false;
b278172f 370 }
df15de21 371 return true;
372 } // function checkInput()
373
3806fa52 374
056ddad7 375 // True if FAILURE
376 function saveAttachedFiles() {
377 global $HTTP_POST_FILES, $attachment_dir, $attachments;
378
379 is_logged_in();
380 $localfilename = GenerateRandomString(32, '', 7);
f972eb46 381 while (file_exists($attachment_dir . $localfilename))
a4fe5de0 382 $localfilename = GenerateRandomString(32, '', 7);
f972eb46 383
056ddad7 384 if (!@rename($HTTP_POST_FILES['attachfile']['tmp_name'], $attachment_dir.$localfilename)) {
385 if (!@copy($HTTP_POST_FILES['attachfile']['tmp_name'], $attachment_dir.$localfilename)) {
386 return true;
387 }
388 }
f972eb46 389
390 $newAttachment['localfilename'] = $localfilename;
391 $newAttachment['remotefilename'] = $HTTP_POST_FILES['attachfile']['name'];
392 $newAttachment['type'] =
393 strtolower($HTTP_POST_FILES['attachfile']['type']);
056ddad7 394
f972eb46 395 $attachments[] = $newAttachment;
056ddad7 396 }
068acdf9 397
398 function SqConvertRussianCharsets(){
399 //
400 // This function is here because Russian Apache is a bastard when it comes to
401 // attachments. The solution is to turn off attachment recoding for multipart
402 // forms and do it manually.
403 // See graf@relhum.org for support.
404 //
405 global $CHARSET, $SOURCE_CHARSET, $send_to, $send_to_cc, $send_to_bcc, $subject, $body;
406 $charset_ary = array("koi8-r" => "k",
407 "windows-1251" => "w",
408 "ibm866" => "a",
409 "ISO-8859-5" => "i");
410 $body = convert_cyr_string($body, $charset_ary[$CHARSET], $charset_ary[$SOURCE_CHARSET]);
411 $send_to = convert_cyr_string($send_to, $charset_ary[$CHARSET], $charset_ary[$SOURCE_CHARSET]);
412 $send_to_cc = convert_cyr_string($send_to_cc, $charset_ary[$CHARSET], $charset_ary[$SOURCE_CHARSET]);
413 $send_to_bcc = convert_cyr_string($send_to_bcc, $charset_ary[$CHARSET], $charset_ary[$SOURCE_CHARSET]);
414 $subject = convert_cyr_string($subject, $charset_ary[$CHARSET], $charset_ary[$SOURCE_CHARSET]);
415 } // end SqConvertRussianCharsets()
416
417 // Russian Apache sets $CHARSET. See if this is Russian Apache.
418 // If so, check if the source charset (koi8-r) is different from the
419 // one submitted by the browser. If so, recode the parts of the form
420 // to the needed format so SM can proceed and not mangle the cyrillic
421 // input.
422 // See graf@relhum.org for support.
423 //
d0717693 424 if (isset($CHARSET) && $CHARSET != $SOURCE_CHARSET) SqConvertRussianCharsets();
068acdf9 425
23fd3c8e 426 if (!isset($mailbox) || $mailbox == "" || ($mailbox == "None"))
dcb7f454 427 $mailbox = "INBOX";
3806fa52 428
f972eb46 429 if (isset($send)) {
245a6892 430 if (isset($HTTP_POST_FILES['attachfile']) &&
431 $HTTP_POST_FILES['attachfile']['tmp_name'] &&
78b4216e 432 $HTTP_POST_FILES['attachfile']['tmp_name'] != 'none')
056ddad7 433 $AttachFailure = saveAttachedFiles();
a7ea7540 434 if (checkInput(false) && !isset($AttachFailure)) {
35d520d3 435 $urlMailbox = urlencode (trim($mailbox));
436 if (! isset($reply_id))
437 $reply_id = 0;
ebab5342 438 // Set $default_charset to correspond with the user's selection
439 // of language interface.
440 set_my_charset();
441 sendMessage($send_to, $send_to_cc, $send_to_bcc, $subject, $body, $reply_id);
966286ae 442 header ("Location: right_main.php?mailbox=$urlMailbox&sort=$sort&startMessage=1");
df15de21 443 } else {
01aab860 444 //$imapConnection = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
dcb7f454 445 displayPageHeader($color, $mailbox);
056ddad7 446
447 if ($AttachFailure)
448 plain_error_message(_("Could not move/copy file. File not attached"), $color);
449
0ad7dbda 450 checkInput(true);
451
df15de21 452 showInputForm();
01aab860 453 //sqimap_logout($imapConnection);
7c6cb7ca 454 }
245a6892 455 } else if (isset($html_addr_search_done)) {
3c13b9fb 456 is_logged_in();
dcb7f454 457 displayPageHeader($color, $mailbox);
3806fa52 458
e53f7484 459 if (isset($send_to_search) && is_array($send_to_search))
460 {
461 for ($i=0; $i < count($send_to_search); $i++) {
462 if ($send_to)
463 $send_to .= ", ";
464 $send_to .= $send_to_search[$i];
465 }
6c7fd6ca 466 }
467
e53f7484 468 if (isset($send_to_cc_search) && is_array($send_to_cc_search))
469 {
470 for ($i=0; $i < count($send_to_cc_search); $i++) {
471 if ($send_to_cc)
472 $send_to_cc .= ", ";
473 $send_to_cc .= $send_to_cc_search[$i];
474 }
6c7fd6ca 475 }
476
e53f7484 477 if (isset($send_to_bcc_search) && is_array($send_to_bcc_search))
478 {
479 for ($i=0; $i < count($send_to_bcc_search); $i++) {
480 if ($send_to_bcc)
481 $send_to_bcc .= ", ";
482 $send_to_bcc .= $send_to_bcc_search[$i];
483 }
a98bed68 484 }
485
3806fa52 486 showInputForm();
245a6892 487 } else if (isset($html_addr_search)) {
591d2a88 488 // I am using an include so as to elminiate an extra unnecessary click. If you
489 // can think of a better way, please implement it.
2037f4f3 490 include ("./addrbook_search_html.php");
4ba45d11 491 } else if (isset($attach)) {
056ddad7 492 if (saveAttachedFiles())
22ef7536 493 plain_error_message(_("Could not move/copy file. File not attached"), $color);
21bc0570 494 displayPageHeader($color, $mailbox);
4ba45d11 495 showInputForm();
496 } else if (isset($do_delete)) {
3c13b9fb 497 is_logged_in();
dcb7f454 498 displayPageHeader($color, $mailbox);
fc3348ac 499
f972eb46 500 if (isset($delete) && is_array($delete))
501 {
502 foreach($delete as $index)
503 {
504 unlink ($attachment_dir.$attachments[$index]['localfilename']);
505 unset ($attachments[$index]);
506 }
4ba45d11 507 }
4bfed9f3 508
4ba45d11 509 showInputForm();
510 } else {
991a059e 511 // This handles the default case as well as the error case
512 // (they had the same code) --> if (isset($smtpErrors))
513 $imapConnection = sqimap_login($username, $key, $imapServerAddress,
514 $imapPort, 0);
dcb7f454 515 displayPageHeader($color, $mailbox);
fc3348ac 516
b57c4e63 517 $newmail = true;
f972eb46 518
519 ClearAttachments();
520
991a059e 521 if (isset($forward_id) && $forward_id && isset($ent_num) && $ent_num)
522 getAttachments(0);
5713b4f9 523
1220e677 524 newMail();
4ba45d11 525 showInputForm();
1195c340 526 sqimap_logout($imapConnection);
4ba45d11 527 }
f972eb46 528
529
530
531
532 function ClearAttachments()
533 {
534 global $attachments, $attachment_dir;
535
536 foreach ($attachments as $info)
537 {
538 if (file_exists($attachment_dir . $info['localfilename']))
539 {
540 unlink($attachment_dir . $info['localfilename']);
541 }
542 }
543
544 $attachments = array();
545 }
546
da79853a 547?>