| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * retrievalerror.php |
| 5 | * |
| 6 | * Copyright (c) 1999-2001 The SquirrelMail Development 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 | /*****************************************************************/ |
| 18 | /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/ |
| 19 | /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/ |
| 20 | /*** + Base level indent should begin at left margin, as ***/ |
| 21 | /*** the require_once below looks. ***/ |
| 22 | /*** + All identation should consist of four space blocks ***/ |
| 23 | /*** + Tab characters are evil. ***/ |
| 24 | /*** + all comments should use "slash-star ... star-slash" ***/ |
| 25 | /*** style -- no pound characters, no slash-slash style ***/ |
| 26 | /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/ |
| 27 | /*** ALWAYS USE { AND } CHARACTERS!!! ***/ |
| 28 | /*** + Please use ' instead of ", when possible. Note " ***/ |
| 29 | /*** should always be used in _( ) function calls. ***/ |
| 30 | /*** Thank you for your help making the SM code more readable. ***/ |
| 31 | /*****************************************************************/ |
| 32 | |
| 33 | require_once('../src/validate.php'); |
| 34 | require_once("../functions/imap.php"); |
| 35 | require_once("../functions/smtp.php"); |
| 36 | require_once("../functions/page_header.php"); |
| 37 | require_once("../src/load_prefs.php"); |
| 38 | |
| 39 | $destination = "retrievalerror@squirrelmail.org"; |
| 40 | |
| 41 | $attachments = array(); |
| 42 | |
| 43 | |
| 44 | function ClearAttachments() { |
| 45 | global $attachments, $attachment_dir, $username; |
| 46 | |
| 47 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 48 | foreach ($attachments as $info) { |
| 49 | $attached_file = "$hashed_attachment_dir/$info[localfilename]"; |
| 50 | if (file_exists($attached_file)) { |
| 51 | unlink($attached_file); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | $attachments = array(); |
| 56 | } |
| 57 | |
| 58 | $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0); |
| 59 | sqimap_mailbox_select($imap_stream, $mailbox); |
| 60 | $sid = sqimap_session_id(); |
| 61 | fputs ($imap_stream, "$sid FETCH $passed_id BODY[]\r\n"); |
| 62 | $data = sqimap_read_data ($imap_stream, $sid, true, $response, $message); |
| 63 | sqimap_logout($imap_stream); |
| 64 | $topline2 = array_shift($data); |
| 65 | $thebastard = implode('', $data); |
| 66 | |
| 67 | |
| 68 | $hashed_attachment_dir = getHashedDir($username, $attachment_dir); |
| 69 | $localfilename = GenerateRandomString(32, '', 7); |
| 70 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 71 | while (file_exists($full_localfilename)) { |
| 72 | $localfilename = GenerateRandomString(32, '', 7); |
| 73 | $full_localfilename = "$hashed_attachment_dir/$localfilename"; |
| 74 | } |
| 75 | |
| 76 | // Write Attachment to file |
| 77 | $fp = fopen ($full_localfilename, 'w'); |
| 78 | fputs ($fp, $thebastard); |
| 79 | fclose ($fp); |
| 80 | |
| 81 | $newAttachment = array(); |
| 82 | $newAttachment['localfilename'] = $localfilename; |
| 83 | $newAttachment['remotefilename'] = 'message.duh'; |
| 84 | $newAttachment['type'] = 'application/octet-stream'; |
| 85 | $attachments[] = $newAttachment; |
| 86 | |
| 87 | |
| 88 | $body = "Response: $response\n" . |
| 89 | "Message: $message\n" . |
| 90 | "FETCH line: $topline\n" . |
| 91 | "Server Type: $imap_server_type\n"; |
| 92 | |
| 93 | $imap_stream = fsockopen ($imapServerAddress, $imapPort, &$error_number, &$error_string); |
| 94 | $server_info = fgets ($imap_stream, 1024); |
| 95 | if ($imap_stream) |
| 96 | { |
| 97 | $body .= " Server info: $server_info"; |
| 98 | fputs ($imap_stream, "a001 CAPABILITY\r\n"); |
| 99 | $read = fgets($imap_stream, 1024); |
| 100 | $list = explode(' ', $read); |
| 101 | array_shift($list); |
| 102 | array_shift($list); |
| 103 | $read = implode(' ', $list); |
| 104 | $body .= " Capabilities: $read"; |
| 105 | fputs ($imap_stream, "a002 LOGOUT\r\n"); |
| 106 | fclose($imap_stream); |
| 107 | } |
| 108 | |
| 109 | $body .= "\nFETCH line for gathering the whole message: $topline2\n"; |
| 110 | |
| 111 | |
| 112 | sendMessage($destination, "", "", "submitted message", $body, 0); |
| 113 | |
| 114 | |
| 115 | |
| 116 | |
| 117 | displayPageHeader($color, $mailbox); |
| 118 | |
| 119 | $par = "mailbox=".urlencode($mailbox)."&passed_id=$passed_id"; |
| 120 | if (isset($where) && isset($what)) { |
| 121 | $par .= "&where=".urlencode($where)."&what=".urlencode($what); |
| 122 | } else { |
| 123 | $par .= "&startMessage=$startMessage&show_more=0"; |
| 124 | } |
| 125 | |
| 126 | echo '<BR>The message has been submitted to the developers knowledgebase!<BR>' . |
| 127 | 'Thank you very much<BR>' . |
| 128 | 'Please submit every message only once<BR>' . |
| 129 | "<A HREF=\"../src/read_body.php?$par\">View the message</A><BR>"; |
| 130 | |
| 131 | ?> |