d2623abd4d6bd2e2c29257dee8fb96b73293dc4d
[squirrelmail.git] / src / retrievalerror.php
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;
46
47 foreach ($attachments as $info) {
48 if (file_exists($attachment_dir . $info['localfilename'])) {
49 unlink($attachment_dir . $info['localfilename']);
50 }
51 }
52
53 $attachments = array();
54 }
55
56 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
57 sqimap_mailbox_select($imap_stream, $mailbox);
58 $sid = sqimap_session_id();
59 fputs ($imap_stream, "$sid FETCH $passed_id BODY[]\r\n");
60 $data = sqimap_read_data ($imap_stream, $sid, true, $response, $message);
61 sqimap_logout($imap_stream);
62 $topline2 = array_shift($data);
63 $thebastard = implode('', $data);
64
65
66
67 $localfilename = GenerateRandomString(32, '', 7);
68 while (file_exists($attachment_dir . $localfilename))
69 $localfilename = GenerateRandomString(32, '', 7);
70 // Write Attachment to file
71 $fp = fopen ($attachment_dir.$localfilename, 'w');
72 fputs ($fp, $thebastard);
73 fclose ($fp);
74
75 $newAttachment = array();
76 $newAttachment['localfilename'] = $localfilename;
77 $newAttachment['remotefilename'] = 'message.duh';
78 $newAttachment['type'] = 'application/octet-stream';
79 $attachments[] = $newAttachment;
80
81
82 $body = "Response: $response\n" .
83 "Message: $message\n" .
84 "FETCH line: $topline\n" .
85 "Server Type: $imap_server_type\n";
86
87 $imap_stream = fsockopen ($imapServerAddress, $imapPort, &$error_number, &$error_string);
88 $server_info = fgets ($imap_stream, 1024);
89 if ($imap_stream)
90 {
91 $body .= " Server info: $server_info";
92 fputs ($imap_stream, "a001 CAPABILITY\r\n");
93 $read = fgets($imap_stream, 1024);
94 $list = explode(' ', $read);
95 array_shift($list);
96 array_shift($list);
97 $read = implode(' ', $list);
98 $body .= " Capabilities: $read";
99 fputs ($imap_stream, "a002 LOGOUT\r\n");
100 fclose($imap_stream);
101 }
102
103 $body .= "\nFETCH line for gathering the whole message: $topline2\n";
104
105
106 sendMessage($destination, "", "", "submitted message", $body, 0);
107
108
109
110
111 displayPageHeader($color, $mailbox);
112
113 $par = "mailbox=".urlencode($mailbox)."&passed_id=$passed_id";
114 if (isset($where) && isset($what)) {
115 $par .= "&where=".urlencode($where)."&what=".urlencode($what);
116 } else {
117 $par .= "&startMessage=$startMessage&show_more=0";
118 }
119
120 echo '<BR>The message has been submitted to the developers knowledgebase!<BR>' .
121 'Thank you very much<BR>' .
122 'Please submit every message only once<BR>' .
123 "<A HREF=\"../src/read_body.php?$par\">View the message</A><BR>";
124
125 ?>