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