57fc68413fb9c1c95200ccd6d9c72a0f9a0e23d4
[squirrelmail.git] / src / retrievalerror.php
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 /* Path for SquirrelMail required files. */
18 define('SM_PATH','../');
19
20 /* SquirrelMail required files. */
21 require_once(SM_PATH . 'include/validate.php');
22 require_once(SM_PATH . 'functions/imap.php');
23 require_once(SM_PATH . 'functions/smtp.php');
24 require_once(SM_PATH . 'functions/page_header.php');
25 require_once(SM_PATH . 'include/load_prefs.php');
26
27 $destination = 'retrievalerror@squirrelmail.org';
28 $attachments = array();
29
30 /* globals */
31
32 $key = $_COOKIE['key'];
33 $username = $_SESSION['username'];
34 $onetimepad = $_SESSION['onetimepad'];
35
36 $mailbox = $_GET['mailbox'];
37 $passed_id = $_GET['passed_id'];
38 $startMessage = $_GET['startMessage'];
39 $show_more = $_GET['show_more'];
40 $response = $_GET['response'];
41 $message = $_GET['message'];
42 $topline = $_GET['topline'];
43
44 if(isset($_GET['where'])) {
45 $where = $_GET['where'];
46 }
47 if(isset($_GET['what'])) {
48 $what = $_GET['what'];
49 }
50
51 /* end globals */
52
53 function ClearAttachments() {
54 global $attachments, $attachment_dir, $username;
55
56 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
57 foreach ($attachments as $info) {
58 $attached_file = "$hashed_attachment_dir/$info[localfilename]";
59 if (file_exists($attached_file)) {
60 unlink($attached_file);
61 }
62 }
63
64 $attachments = array();
65 }
66
67 $imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 0);
68 sqimap_mailbox_select($imap_stream, $mailbox);
69 $sid = sqimap_session_id();
70 fputs ($imap_stream, "$sid FETCH $passed_id BODY[]\r\n");
71 $data = sqimap_read_data ($imap_stream, $sid, true, $response, $message);
72 sqimap_logout($imap_stream);
73 $topline2 = array_shift($data);
74 $thebastard = implode('', $data);
75
76 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
77 $localfilename = GenerateRandomString(32, '', 7);
78 $full_localfilename = "$hashed_attachment_dir/$localfilename";
79 while (file_exists($full_localfilename)) {
80 $localfilename = GenerateRandomString(32, '', 7);
81 $full_localfilename = "$hashed_attachment_dir/$localfilename";
82 }
83
84 /* Write Attachment to file */
85 $fp = fopen ($full_localfilename, 'wb');
86 fputs ($fp, $thebastard);
87 fclose ($fp);
88
89 $newAttachment = array();
90 $newAttachment['localfilename'] = $localfilename;
91 $newAttachment['remotefilename'] = 'message.duh';
92 $newAttachment['type'] = 'application/octet-stream';
93 $attachments[] = $newAttachment;
94
95 $body = "Response: $response\n" .
96 "Message: $message\n" .
97 "FETCH line: $topline\n" .
98 "Server Type: $imap_server_type\n";
99
100 $imap_stream = fsockopen ($imapServerAddress, $imapPort, &$error_number, &$error_string);
101 $server_info = fgets ($imap_stream, 1024);
102 if ($imap_stream) {
103 $body .= " Server info: $server_info";
104 fputs ($imap_stream, "a001 CAPABILITY\r\n");
105 $read = fgets($imap_stream, 1024);
106 $list = explode(' ', $read);
107 array_shift($list);
108 array_shift($list);
109 $read = implode(' ', $list);
110 $body .= " Capabilities: $read";
111 fputs ($imap_stream, "a002 LOGOUT\r\n");
112 fclose($imap_stream);
113 }
114
115 $body .= "\nFETCH line for gathering the whole message: $topline2\n";
116
117 sendMessage($destination, '', '', 'submitted message', $body, False, 0);
118
119 displayPageHeader($color, $mailbox);
120
121 $par = 'mailbox='.urlencode($mailbox)."&amp;passed_id=$passed_id";
122 if (isset($where) && isset($what)) {
123 $par .= '&amp;where='.urlencode($where).'&amp;what='.urlencode($what);
124 } else {
125 $par .= "&amp;startMessage=$startMessage&amp;show_more=0";
126 }
127
128 echo '<BR>The message has been submitted to the developers knowledgebase!<BR>' .
129 'Thank you very much<BR>' .
130 'Please submit every message only once<BR>' .
131 "<A HREF=\"../src/read_body.php?$par\">View the message</A><BR>";
132
133 ?>