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