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