| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * retrievalerror.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2002 The SquirrelMail Project Team |
| 7 | * Licensed under the GNU GPL. For full terms see the file COPYING. |
| 8 | * |
| 9 | * Submits a message which Squirrelmail couldn't handle |
| 10 | * because of malformedness of the message |
| 11 | * sends it to retrievalerror@squirrelmail.org |
| 12 | * Of course, this only happens when the end user has chosen to do so |
| 13 | * |
| 14 | * $Id$ |
| 15 | */ |
| 16 | |
| 17 | require_once('../src/validate.php'); |
| 18 | require_once('../functions/imap.php'); |
| 19 | require_once('../functions/smtp.php'); |
| 20 | require_once('../functions/page_header.php'); |
| 21 | require_once('../src/load_prefs.php'); |
| 22 | |
| 23 | $destination = 'retrievalerror@squirrelmail.org'; |
| 24 | |
| 25 | $attachments = array(); |
| 26 | |
| 27 | function ClearAttachments() { |
| 28 | global $attachments, $attachment_dir, $username; |
| 29 | |
| 30 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 31 | foreach ($attachments as $info) { |
| 32 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
| 33 | if (file_exists($attached_file)) { |
| 34 | unlink($attached_file); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | $attachments = array(); |
| 39 | } |
| 40 | |
| 41 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 42 | sqimap_mailbox_select($imap_stream, $mailbox); |
| 43 | $sid = sqimap_session_id(); |
| 44 | fputs ($imap_stream, "$sid FETCH $passed_id BODY[]\r\n"); |
| 45 | $data = sqimap_read_data ($imap_stream, $sid, true, $response, $message); |
| 46 | sqimap_logout($imap_stream); |
| 47 | $topline2 = array_shift($data); |
| 48 | $thebastard = implode('', $data); |
| 49 | |
| 50 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 51 | $localfilename = GenerateRandomString(32, '', 7); |
| 52 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 53 | while (file_exists($full_localfilename)) { |
| 54 | $localfilename = GenerateRandomString(32, '', 7); |
| 55 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 56 | } |
| 57 | |
| 58 | /* Write Attachment to file */ |
| 59 | $fp = fopen ($full_localfilename, 'w'); |
| 60 | fputs ($fp, $thebastard); |
| 61 | fclose ($fp); |
| 62 | |
| 63 | $newAttachment = array(); |
| 64 | $newAttachment['localfilename'] = $localfilename; |
| 65 | $newAttachment['remotefilename'] = 'message.duh'; |
| 66 | $newAttachment['type'] = 'application/octet-stream'; |
| 67 | $attachments[] = $newAttachment; |
| 68 | |
| 69 | $body = "Response: $response\n" . |
| 70 | "Message: $message\n" . |
| 71 | "FETCH line: $topline\n" . |
| 72 | "Server Type: $imap_server_type\n"; |
| 73 | |
| 74 | $imap_stream = fsockopen ($imapServerAddress, $imapPort, &$error_number, &$error_string); |
| 75 | $server_info = fgets ($imap_stream, 1024); |
| 76 | if ($imap_stream) { |
| 77 | $body .= " Server info: $server_info"; |
| 78 | fputs ($imap_stream, "a001 CAPABILITY\r\n"); |
| 79 | $read = fgets($imap_stream, 1024); |
| 80 | $list = explode(' ', $read); |
| 81 | array_shift($list); |
| 82 | array_shift($list); |
| 83 | $read = implode(' ', $list); |
| 84 | $body .= " Capabilities: $read"; |
| 85 | fputs ($imap_stream, "a002 LOGOUT\r\n"); |
| 86 | fclose($imap_stream); |
| 87 | } |
| 88 | |
| 89 | $body .= "\nFETCH line for gathering the whole message: $topline2\n"; |
| 90 | |
| 91 | sendMessage($destination, '', '', 'submitted message', $body, 0); |
| 92 | |
| 93 | displayPageHeader($color, $mailbox); |
| 94 | |
| 95 | $par = 'mailbox='.urlencode($mailbox)."&passed_id=$passed_id"; |
| 96 | if (isset($where) && isset($what)) { |
| 97 | $par .= '&where='.urlencode($where).'&what='.urlencode($what); |
| 98 | } else { |
| 99 | $par .= "&startMessage=$startMessage&show_more=0"; |
| 100 | } |
| 101 | |
| 102 | echo '<BR>The message has been submitted to the developers knowledgebase!<BR>' . |
| 103 | 'Thank you very much<BR>' . |
| 104 | 'Please submit every message only once<BR>' . |
| 105 | "<A HREF=\"../src/read_body.php?$par\">View the message</A><BR>"; |
| 106 | |
| 107 | ?> |