added authenticated smtp server support
[squirrelmail.git] / functions / smtp.php
CommitLineData
59177427 1<?php
b8ea4ed6 2 /** smtp.php
3 **
4 ** This contains all the functions needed to send messages through
36fa79c8 5 ** an smtp server or sendmail.
245a6892 6 **
7 ** $Id$
b8ea4ed6 8 **/
9
d068c0ec 10 $smtp_php = true;
a4102fd7 11 if (!isset($addressbook_php))
12 include('../functions/addressbook.php');
465db5d7 13
31afdefb 14 // This should most probably go to some initialization...
15 if (ereg("^([^@%/]+)[@%/](.+)$", $username, $usernamedata)) {
16 $popuser = $usernamedata[1];
17 $domain = $usernamedata[2];
18 unset($usernamedata);
19 } else {
20 $popuser = $username;
21 }
22 // We need domain for smtp
23 if (!$domain)
ec9f1c41 24 $domain = getenv('HOSTNAME');
31afdefb 25
df15de21 26 // Returns true only if this message is multipart
27 function isMultipart () {
4ba45d11 28 global $attachments;
29
30 if (count($attachments)>0)
31 return true;
32 else
33 return false;
df15de21 34 }
35
a4102fd7 36 // looks up aliases in the addressbook and expands them to
37 // the full address.
38 function expandAddrs ($array) {
39 $abook = addressbook_init();
40 for ($i=0; $i < count($array); $i++) {
41 $result = $abook->lookup($array[$i]);
42 $ret = "";
43 if (isset($result['email'])) {
44 if (isset($result['name'])) {
45 $ret = '"'.$result['name'].'" ';
46 }
47 $ret .= '<'.$result['email'].'>';
48 $array[$i] = $ret;
49 }
18e206dd 50 else
51 {
52 $array[$i] = '<' . $array[$i] . '>';
53 }
a4102fd7 54 }
55 return $array;
56 }
57
df15de21 58 // Attach the files that are due to be attached
4ba45d11 59 function attachFiles ($fp) {
c3c37167 60 global $attachments, $attachment_dir;
4ba45d11 61
7b67334e 62 $length = 0;
63
a7d75834 64 if (isMultipart()) {
f972eb46 65 foreach ($attachments as $info)
66 {
7d50f13c 67 if (isset($info['type']))
68 $filetype = $info['type'];
69 else
ec9f1c41 70 $filetype = 'application/octet-stream';
a7d75834 71
ec9f1c41 72 $header = '--'.mimeBoundary()."\r\n";
f972eb46 73 $header .= "Content-Type: $filetype; name=\"" .
74 $info['remotefilename'] . "\"\r\n";
75 $header .= "Content-Disposition: attachment; filename=\"" .
76 $info['remotefilename'] . "\"\r\n";
a7d75834 77 $header .= "Content-Transfer-Encoding: base64\r\n\r\n";
78 fputs ($fp, $header);
79 $length += strlen($header);
80
f972eb46 81 $file = fopen ($attachment_dir . $info['localfilename'], 'r');
a7d75834 82 while ($tmp = fread($file, 570)) {
83 $encoded = chunk_split(base64_encode($tmp));
84 $length += strlen($encoded);
85 fputs ($fp, $encoded);
86 }
87 fclose ($file);
7b67334e 88 }
4ba45d11 89 }
7b67334e 90
91 return $length;
df15de21 92 }
93
a7d75834 94 // Delete files that are uploaded for attaching
95 function deleteAttachments() {
96 global $attachments, $attachment_dir;
97
98 if (isMultipart()) {
99 reset($attachments);
100 while (list($localname, $remotename) = each($attachments)) {
101 if (!ereg ("\\/", $localname)) {
102 unlink ($attachment_dir.$localname);
ec9f1c41 103 unlink ($attachment_dir.$localname.'.info');
a7d75834 104 }
105 }
106 }
107 }
108
df15de21 109 // Return a nice MIME-boundary
110 function mimeBoundary () {
7b67334e 111 static $mimeBoundaryString;
df15de21 112
113 if ($mimeBoundaryString == "") {
ed865adf 114 $mimeBoundaryString = "----=_" .
fe53c3b9 115 GenerateRandomString(60, '\'()+,-./:=?_', 7);
465db5d7 116 }
df15de21 117
118 return $mimeBoundaryString;
465db5d7 119 }
120
24397423 121 /* Time offset for correct timezone */
122 function timezone () {
b0d1b51e 123 global $invert_time;
124
ec9f1c41 125 $diff_second = date('Z');
d47b2518 126 if ($invert_time)
127 $diff_second = - $diff_second;
24397423 128 if ($diff_second > 0)
ec9f1c41 129 $sign = '+';
24397423 130 else
ec9f1c41 131 $sign = '-';
24397423 132
133 $diff_second = abs($diff_second);
134
135 $diff_hour = floor ($diff_second / 3600);
136 $diff_minute = floor (($diff_second-3600*$diff_hour) / 60);
137
ec9f1c41 138 $zonename = '('.strftime('%Z').')';
24397423 139 $result = sprintf ("%s%02d%02d %s", $sign, $diff_hour, $diff_minute, $zonename);
140 return ($result);
141 }
142
df15de21 143 /* Print all the needed RFC822 headers */
60994e13 144 function write822Header ($fp, $t, $c, $b, $subject, $more_headers) {
a7d75834 145 global $REMOTE_ADDR, $SERVER_NAME, $REMOTE_PORT;
31afdefb 146 global $data_dir, $username, $popuser, $domain, $version, $useSendmail;
9949206d 147 global $default_charset, $HTTP_VIA, $HTTP_X_FORWARDED_FOR;
a5363806 148 global $REMOTE_HOST;
465db5d7 149
7b67334e 150 // Storing the header to make sure the header is the same
151 // everytime the header is printed.
152 static $header, $headerlength;
153
ec9f1c41 154 if ($header == '') {
a4102fd7 155 $to = expandAddrs(parseAddrs($t));
156 $cc = expandAddrs(parseAddrs($c));
157 $bcc = expandAddrs(parseAddrs($b));
ec9f1c41 158 $reply_to = getPref($data_dir, $username, 'reply_to');
159 $from = getPref($data_dir, $username, 'full_name');
160 $from_addr = getPref($data_dir, $username, 'email_address');
31afdefb 161
ec9f1c41 162 if ($from_addr == '')
163 $from_addr = $popuser.'@'.$domain;
7b67334e 164
165 $to_list = getLineOfAddrs($to);
166 $cc_list = getLineOfAddrs($cc);
167 $bcc_list = getLineOfAddrs($bcc);
8ae331c2 168
78e230b7 169 /* Encoding 8-bit characters and making from line */
d51894be 170 $subject = encodeHeader($subject);
ec9f1c41 171 if ($from == '')
7b67334e 172 $from = "<$from_addr>";
173 else
ec9f1c41 174 $from = '"' . encodeHeader($from) . "\" <$from_addr>";
7b67334e 175
a7d75834 176 /* This creates an RFC 822 date */
7b67334e 177 $date = date("D, j M Y H:i:s ", mktime()) . timezone();
a7d75834 178
179 /* Create a message-id */
ec9f1c41 180 $message_id = '<' . $REMOTE_PORT . '.' . $REMOTE_ADDR . '.';
181 $message_id .= time() . '.squirrel@' . $SERVER_NAME .'>';
7b67334e 182
183 /* Make an RFC822 Received: line */
a5363806 184 if (isset($REMOTE_HOST))
8a2848f0 185 $received_from = "$REMOTE_HOST ([$REMOTE_ADDR])";
a5363806 186 else
8a2848f0 187 $received_from = $REMOTE_ADDR;
a5363806 188
9949206d 189 if (isset($HTTP_VIA) || isset ($HTTP_X_FORWARDED_FOR)) {
ec9f1c41 190 if ($HTTP_X_FORWARDED_FOR == '')
191 $HTTP_X_FORWARDED_FOR = 'unknown';
9949206d 192 $received_from .= " (proxying for $HTTP_X_FORWARDED_FOR)";
193 }
a5363806 194
8a2848f0 195 $header = "Received: from $received_from\r\n";
196 $header .= " (SquirrelMail authenticated user $username)\r\n";
197 $header .= " by $SERVER_NAME with HTTP;\r\n";
198 $header .= " $date\r\n";
7b67334e 199
a7d75834 200 /* Insert the rest of the header fields */
201 $header .= "Message-ID: $message_id\r\n";
7b67334e 202 $header .= "Date: $date\r\n";
203 $header .= "Subject: $subject\r\n";
204 $header .= "From: $from\r\n";
18e206dd 205 $header .= "To: $to_list\r\n"; // Who it's TO
60994e13 206
207 /* Insert headers from the $more_headers array */
208 if(is_array($more_headers)) {
209 reset($more_headers);
210 while(list($h_name, $h_val) = each($more_headers)) {
211 $header .= sprintf("%s: %s\r\n", $h_name, $h_val);
212 }
213 }
214
7b67334e 215 if ($cc_list) {
216 $header .= "Cc: $cc_list\r\n"; // Who the CCs are
df15de21 217 }
7b67334e 218
ec9f1c41 219 if ($reply_to != '')
7b67334e 220 $header .= "Reply-To: $reply_to\r\n";
221
222 if ($useSendmail) {
223 if ($bcc_list) {
224 // BCCs is removed from header by sendmail
225 $header .= "Bcc: $bcc_list\r\n";
226 }
227 }
228
229 $header .= "X-Mailer: SquirrelMail (version $version)\r\n"; // Identify SquirrelMail
230
231 // Do the MIME-stuff
f8308f16 232 $header .= "MIME-Version: 1.0\r\n";
7b67334e 233
234 if (isMultipart()) {
ec9f1c41 235 $header .= 'Content-Type: multipart/mixed; boundary="';
7b67334e 236 $header .= mimeBoundary();
237 $header .= "\"\r\n";
238 } else {
ec9f1c41 239 if ($default_charset != '')
17ce8467 240 $header .= "Content-Type: text/plain; charset=$default_charset\r\n";
241 else
242 $header .= "Content-Type: text/plain;\r\n";
7b67334e 243 $header .= "Content-Transfer-Encoding: 8bit\r\n";
244 }
245 $header .= "\r\n"; // One blank line to separate header and body
df15de21 246
7b67334e 247 $headerlength = strlen($header);
248 }
249
250 // Write the header
251 fputs ($fp, $header);
df15de21 252
7b67334e 253 return $headerlength;
254 }
df15de21 255
7b67334e 256 // Send the body
257 function writeBody ($fp, $passedBody) {
17ce8467 258 global $default_charset;
259
7b67334e 260 $attachmentlength = 0;
261
df15de21 262 if (isMultipart()) {
ec9f1c41 263 $body = '--'.mimeBoundary()."\r\n";
17ce8467 264
265 if ($default_charset != "")
266 $body .= "Content-Type: text/plain; charset=$default_charset\r\n";
267 else
268 $body .= "Content-Type: text/plain\r\n";
269
7b67334e 270 $body .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
d51894be 271 $body .= $passedBody . "\r\n\r\n";
7b67334e 272 fputs ($fp, $body);
273
6441f7c6 274 $attachmentlength = attachFiles($fp);
7b67334e 275
f8cfeb5c 276 if (!isset($postbody)) $postbody = "";
7b67334e 277 $postbody .= "\r\n--".mimeBoundary()."--\r\n\r\n";
278 fputs ($fp, $postbody);
df15de21 279 } else {
d51894be 280 $body = $passedBody . "\r\n";
7b67334e 281 fputs ($fp, $body);
282 $postbody = "\r\n";
283 fputs ($fp, $postbody);
df15de21 284 }
df15de21 285
7b67334e 286 return (strlen($body) + strlen($postbody) + $attachmentlength);
c99c5b31 287 }
465db5d7 288
c99c5b31 289 // Send mail using the sendmail command
60994e13 290 function sendSendmail($t, $c, $b, $subject, $body, $more_headers) {
31afdefb 291 global $sendmail_path, $popuser, $username, $domain;
7b67334e 292
6ebf8b30 293 // Build envelope sender address. Make sure it doesn't contain
294 // spaces or other "weird" chars that would allow a user to
295 // exploit the shell/pipe it is used in.
31afdefb 296 $envelopefrom = "$popuser@$domain";
ec9f1c41 297 $envelopefrom = ereg_replace("[[:blank:]]",'', $envelopefrom);
298 $envelopefrom = ereg_replace("[[:space:]]",'', $envelopefrom);
299 $envelopefrom = ereg_replace("[[:cntrl:]]",'', $envelopefrom);
6ebf8b30 300
c99c5b31 301 // open pipe to sendmail
ec9f1c41 302 $fp = popen (escapeshellcmd("$sendmail_path -t -f$envelopefrom"), 'w');
c99c5b31 303
60994e13 304 $headerlength = write822Header ($fp, $t, $c, $b, $subject, $more_headers);
7b67334e 305 $bodylength = writeBody($fp, $body);
465db5d7 306
307 pclose($fp);
7b67334e 308
0775b17f 309 return ($headerlength + $bodylength);
465db5d7 310 }
311
b8ea4ed6 312 function smtpReadData($smtpConnection) {
313 $read = fgets($smtpConnection, 1024);
314 $counter = 0;
315 while ($read) {
ec9f1c41 316 echo $read . '<BR>';
b8ea4ed6 317 $data[$counter] = $read;
318 $read = fgets($smtpConnection, 1024);
319 $counter++;
320 }
321 }
322
60994e13 323 function sendSMTP($t, $c, $b, $subject, $body, $more_headers) {
31afdefb 324 global $username, $popuser, $domain, $version, $smtpServerAddress, $smtpPort,
d2f4c914 325 $data_dir, $color, $use_authenticating_smtp;
7831268e 326
a4102fd7 327 $to = expandAddrs(parseAddrs($t));
328 $cc = expandAddrs(parseAddrs($c));
329 $bcc = expandAddrs(parseAddrs($b));
ec9f1c41 330 $from_addr = getPref($data_dir, $username, 'email_address');
356d7825 331
31afdefb 332 if (!$from_addr)
333 $from_addr = "$popuser@$domain";
d3cdb279 334
c175e2e4 335 $smtpConnection = fsockopen($smtpServerAddress, $smtpPort, $errorNumber, $errorString);
b8ea4ed6 336 if (!$smtpConnection) {
ec9f1c41 337 echo 'Error connecting to SMTP Server.<br>';
b8ea4ed6 338 echo "$errorNumber : $errorString<br>";
339 exit;
340 }
f8a9394d 341 $tmp = fgets($smtpConnection, 1024);
342 errorCheck($tmp, $smtpConnection);
b8ea4ed6 343
40ee9452 344 $to_list = getLineOfAddrs($to);
345 $cc_list = getLineOfAddrs($cc);
346
347 /** Lets introduce ourselves */
d2f4c914 348 if (! isset ($use_authenticating_smtp)) {
349 fputs($smtpConnection, "HELO $domain\r\n");
350 $tmp = fgets($smtpConnection, 1024);
351 errorCheck($tmp, $smtpConnection);
352 } else {
353 fputs($smtpConnection, "EHLO $domain\r\n");
354 $tmp = fgets($smtpConnection, 1024);
355 errorCheck($tmp, $smtpConnection);
356
357 fputs($smtpConnection, "AUTH LOGIN\r\n");
358 $tmp = fgets($smtpConnection, 1024);
359 errorCheck($tmp, $smtpConnection);
360
361 fputs($smtpConnection, base64_encode ($username) . "\r\n");
362 $tmp = fgets($smtpConnection, 1024);
363 errorCheck($tmp, $smtpConnection);
364
365 fputs($smtpConnection, base64_encode ($OneTimePadDecrypt($key, $onetimepad)) . "\r\n");
366 $tmp = fgets($smtpConnection, 1024);
367 errorCheck($tmp, $smtpConnection);
368 }
7831268e 369
40ee9452 370 /** Ok, who is sending the message? */
f89627f3 371 fputs($smtpConnection, "MAIL FROM: <$from_addr>\r\n");
f8a9394d 372 $tmp = fgets($smtpConnection, 1024);
373 errorCheck($tmp, $smtpConnection);
b8ea4ed6 374
40ee9452 375 /** send who the recipients are */
376 for ($i = 0; $i < count($to); $i++) {
18e206dd 377 fputs($smtpConnection, "RCPT TO: $to[$i]\r\n");
f8a9394d 378 $tmp = fgets($smtpConnection, 1024);
379 errorCheck($tmp, $smtpConnection);
40ee9452 380 }
381 for ($i = 0; $i < count($cc); $i++) {
b4338e67 382 fputs($smtpConnection, "RCPT TO: $cc[$i]\r\n");
f8a9394d 383 $tmp = fgets($smtpConnection, 1024);
384 errorCheck($tmp, $smtpConnection);
40ee9452 385 }
386 for ($i = 0; $i < count($bcc); $i++) {
b4338e67 387 fputs($smtpConnection, "RCPT TO: $bcc[$i]\r\n");
f8a9394d 388 $tmp = fgets($smtpConnection, 1024);
389 errorCheck($tmp, $smtpConnection);
40ee9452 390 }
b8ea4ed6 391
40ee9452 392 /** Lets start sending the actual message */
3379d740 393 fputs($smtpConnection, "DATA\r\n");
f8a9394d 394 $tmp = fgets($smtpConnection, 1024);
395 errorCheck($tmp, $smtpConnection);
7831268e 396
7b67334e 397 // Send the message
60994e13 398 $headerlength = write822Header ($smtpConnection, $t, $c, $b, $subject, $more_headers);
7b67334e 399 $bodylength = writeBody($smtpConnection, $body);
7831268e 400
3379d740 401 fputs($smtpConnection, ".\r\n"); // end the DATA part
f8a9394d 402 $tmp = fgets($smtpConnection, 1024);
403 $num = errorCheck($tmp, $smtpConnection);
3021b626 404 if ($num != 250) {
f8a9394d 405 $tmp = nl2br(htmlspecialchars($tmp));
28010579 406 echo "ERROR<BR>Message not sent!<BR>Reason given: $tmp<BR></BODY></HTML>";
3021b626 407 }
d3cdb279 408
3379d740 409 fputs($smtpConnection, "QUIT\r\n"); // log off
78509c54 410
411 fclose($smtpConnection);
7b67334e 412
413 return ($headerlength + $bodylength);
b8ea4ed6 414 }
3021b626 415
416
f8a9394d 417 function errorCheck($line, $smtpConnection) {
776c7431 418 global $page_header_php;
28010579 419 global $color;
776c7431 420 if (!isset($page_header_php)) {
ec9f1c41 421 include '../functions/page_header.php';
776c7431 422 }
423
f8a9394d 424 // Read new lines on a multiline response
425 $lines = $line;
426 while(ereg("^[0-9]+-", $line)) {
427 $line = fgets($smtpConnection, 1024);
428 $lines .= $line;
429 }
430
3021b626 431 // Status: 0 = fatal
432 // 5 = ok
433
434 $err_num = substr($line, 0, strpos($line, " "));
435 switch ($err_num) {
ec9f1c41 436 case 500: $message = 'Syntax error; command not recognized';
3021b626 437 $status = 0;
438 break;
ec9f1c41 439 case 501: $message = 'Syntax error in parameters or arguments';
3021b626 440 $status = 0;
441 break;
ec9f1c41 442 case 502: $message = 'Command not implemented';
3021b626 443 $status = 0;
444 break;
ec9f1c41 445 case 503: $message = 'Bad sequence of commands';
3021b626 446 $status = 0;
447 break;
ec9f1c41 448 case 504: $message = 'Command parameter not implemented';
3021b626 449 $status = 0;
450 break;
451
452
ec9f1c41 453 case 211: $message = 'System status, or system help reply';
3021b626 454 $status = 5;
455 break;
ec9f1c41 456 case 214: $message = 'Help message';
3021b626 457 $status = 5;
458 break;
459
460
ec9f1c41 461 case 220: $message = 'Service ready';
3021b626 462 $status = 5;
463 break;
ec9f1c41 464 case 221: $message = 'Service closing transmission channel';
3021b626 465 $status = 5;
466 break;
ec9f1c41 467 case 421: $message = 'Service not available, closing chanel';
3021b626 468 $status = 0;
469 break;
470
d2f4c914 471 case 235: return; break;
ec9f1c41 472 case 250: $message = 'Requested mail action okay, completed';
3021b626 473 $status = 5;
474 break;
ec9f1c41 475 case 251: $message = 'User not local; will forward';
3021b626 476 $status = 5;
477 break;
d2f4c914 478 case 334: return; break;
ec9f1c41 479 case 450: $message = 'Requested mail action not taken: mailbox unavailable';
3021b626 480 $status = 0;
481 break;
ec9f1c41 482 case 550: $message = 'Requested action not taken: mailbox unavailable';
3021b626 483 $status = 0;
484 break;
ec9f1c41 485 case 451: $message = 'Requested action aborted: error in processing';
3021b626 486 $status = 0;
487 break;
ec9f1c41 488 case 551: $message = 'User not local; please try forwarding';
3021b626 489 $status = 0;
490 break;
ec9f1c41 491 case 452: $message = 'Requested action not taken: insufficient system storage';
3021b626 492 $status = 0;
493 break;
ec9f1c41 494 case 552: $message = 'Requested mail action aborted: exceeding storage allocation';
3021b626 495 $status = 0;
496 break;
ec9f1c41 497 case 553: $message = 'Requested action not taken: mailbox name not allowed';
3021b626 498 $status = 0;
499 break;
ec9f1c41 500 case 354: $message = 'Start mail input; end with .';
3021b626 501 $status = 5;
502 break;
ec9f1c41 503 case 554: $message = 'Transaction failed';
3021b626 504 $status = 0;
505 break;
434666c7 506 default: $message = 'Unknown response: '. nl2br(htmlspecialchars($lines));
3021b626 507 $status = 0;
ec9f1c41 508 $error_num = '001';
3021b626 509 break;
510 }
511
512 if ($status == 0) {
ec9f1c41 513 displayPageHeader($color, 'None');
514 echo '<TT>';
776c7431 515 echo "<br><b><font color=\"$color[1]\">ERROR</font></b><br><br>";
3021b626 516 echo "&nbsp;&nbsp;&nbsp;<B>Error Number: </B>$err_num<BR>";
517 echo "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<B>Reason: </B>$message<BR>";
f8a9394d 518 $lines = nl2br(htmlspecialchars($lines));
519 echo "<B>Server Response: </B>$lines<BR>";
ec9f1c41 520 echo '<BR>MAIL NOT SENT';
521 echo '</TT></BODY></HTML>';
3021b626 522 exit;
523 }
524 return $err_num;
525 }
df15de21 526
966286ae 527 function sendMessage($t, $c, $b, $subject, $body, $reply_id) {
d2f4c914 528 global $useSendmail, $msg_id, $is_reply, $mailbox, $onetimepad;
6441f7c6 529 global $data_dir, $username, $domain, $key, $version, $sent_folder, $imapServerAddress, $imapPort;
60994e13 530 $more_headers = Array();
d1b8b679 531
966286ae 532 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 1);
60994e13 533
214e1343 534 if (isset($reply_id) && $reply_id) {
966286ae 535 sqimap_mailbox_select ($imap_stream, $mailbox);
ec9f1c41 536 sqimap_messages_flag ($imap_stream, $reply_id, $reply_id, 'Answered');
60994e13 537
c95df380 538 // Insert In-Reply-To and References headers if the
539 // message-id of the message we reply to is set (longer than "<>")
540 // The References header should really be the old Referenced header
541 // with the message ID appended, but it can be only the message ID too.
542 $hdr = sqimap_get_small_header ($imap_stream, $reply_id, false);
543 if(strlen($hdr->message_id) > 2) {
ec9f1c41 544 $more_headers['In-Reply-To'] = $hdr->message_id;
545 $more_headers['References'] = $hdr->message_id;
c95df380 546 }
966286ae 547 }
8ae331c2 548
af8eba43 549 // In order to remove the problem of users not able to create
550 // messages with "." on a blank line, RFC821 has made provision
551 // in section 4.5.2 (Transparency).
146e0c45 552 $body = ereg_replace("\n\\.", "\n..", $body);
553 $body = ereg_replace("^\\.", "..", $body);
af8eba43 554
8ae331c2 555 // this is to catch all plain \n instances and
556 // replace them with \r\n.
557 $body = ereg_replace("\r\n", "\n", $body);
558 $body = ereg_replace("\n", "\r\n", $body);
3a8c414d 559
8ae331c2 560 if ($useSendmail) {
60994e13 561 $length = sendSendmail($t, $c, $b, $subject, $body, $more_headers);
df15de21 562 } else {
60994e13 563 $length = sendSMTP($t, $c, $b, $subject, $body, $more_headers);
df15de21 564 }
d1b8b679 565
2966f172 566 if (sqimap_mailbox_exists ($imap_stream, $sent_folder)) {
567 sqimap_append ($imap_stream, $sent_folder, $length);
60994e13 568 write822Header ($imap_stream, $t, $c, $b, $subject, $more_headers);
8ae331c2 569 writeBody ($imap_stream, $body);
2966f172 570 sqimap_append_done ($imap_stream);
8ae331c2 571 }
572 sqimap_logout($imap_stream);
a7d75834 573 // Delete the files uploaded for attaching (if any).
f972eb46 574 ClearAttachments();
df15de21 575 }
8ae331c2 576
434666c7 577?>