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