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