More rg=0
[squirrelmail.git] / src / retrievalerror.php
CommitLineData
a019eeb8 1<?php
895905c0 2
35586184 3/**
4 * retrievalerror.php
5 *
15e6162e 6 * Copyright (c) 1999-2002 The SquirrelMail Project Team
35586184 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
86725763 17/* Path for SquirrelMail required files. */
18define('SM_PATH','../');
19
20/* SquirrelMail required files. */
08185f2a 21require_once(SM_PATH . 'include/validate.php');
86725763 22require_once(SM_PATH . 'functions/imap.php');
23require_once(SM_PATH . 'functions/smtp.php');
24require_once(SM_PATH . 'functions/page_header.php');
08185f2a 25require_once(SM_PATH . 'include/load_prefs.php');
32f4e318 26
feb8ce79 27$destination = 'retrievalerror@squirrelmail.org';
32f4e318 28$attachments = array();
29
0b97a708 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
44if(isset($_GET['where'])) {
45 $where = $_GET['where'];
46}
47if(isset($_GET['what'])) {
48 $what = $_GET['what'];
49}
50
51/* end globals */
52
32f4e318 53function 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);
68sqimap_mailbox_select($imap_stream, $mailbox);
69$sid = sqimap_session_id();
70fputs ($imap_stream, "$sid FETCH $passed_id BODY[]\r\n");
71$data = sqimap_read_data ($imap_stream, $sid, true, $response, $message);
72sqimap_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";
79while (file_exists($full_localfilename)) {
80 $localfilename = GenerateRandomString(32, '', 7);
81 $full_localfilename = "$hashed_attachment_dir/$localfilename";
82}
83
84/* Write Attachment to file */
81d79073 85$fp = fopen ($full_localfilename, 'wb');
32f4e318 86fputs ($fp, $thebastard);
87fclose ($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);
102if ($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
4041157c 117sendMessage($destination, '', '', 'submitted message', $body, False, 0);
32f4e318 118
119displayPageHeader($color, $mailbox);
120
5e9e90fd 121$par = 'mailbox='.urlencode($mailbox)."&amp;passed_id=$passed_id";
32f4e318 122if (isset($where) && isset($what)) {
5e9e90fd 123 $par .= '&amp;where='.urlencode($where).'&amp;what='.urlencode($what);
32f4e318 124} else {
5e9e90fd 125 $par .= "&amp;startMessage=$startMessage&amp;show_more=0";
32f4e318 126}
127
128echo '<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
5e9e90fd 133?>