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