6139a097982b803749fcae55c37b12d3d0d126e1
[squirrelmail.git] / plugins / spamcop / spamcop.php
1 <?php
2 /**
3 ** spamcop.php -- SpamCop plugin
4 **
5 ** Copyright (c) 1999-2003 The SquirrelMail development team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
8 ** $Id$
9 **/
10
11 define('SM_PATH','../../');
12
13 /* SquirrelMail required files. */
14 require_once(SM_PATH . 'include/validate.php');
15 require_once(SM_PATH . 'functions/imap.php');
16
17 function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
18 $passed_ent_id='', $imapConnection) {
19 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
20
21 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
22 if (!$passed_ent_id) {
23 $body_a = sqimap_run_command($imapConnection,
24 'FETCH '.$passed_id.' RFC822',
25 TRUE, $response, $readmessage,
26 $uid_support);
27 } else {
28 $body_a = sqimap_run_command($imapConnection,
29 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
30 TRUE, $response, $readmessage, $uid_support);
31 $message = $message->parent;
32 }
33 if ($response = 'OK') {
34 $subject = encodeHeader($message->rfc822_header->subject);
35 array_shift($body_a);
36 $body = implode('', $body_a) . "\r\n";
37
38 $localfilename = GenerateRandomString(32, 'FILE', 7);
39 $full_localfilename = "$hashed_attachment_dir/$localfilename";
40 $fp = fopen( $full_localfilename, 'w');
41 fwrite ($fp, $body);
42 fclose($fp);
43
44 /* dirty relative dir fix */
45 if (substr($attachment_dir,0,3) == '../') {
46 $attachment_dir = substr($attachment_dir,3);
47 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
48 }
49 $full_localfilename = "$hashed_attachment_dir/$localfilename";
50
51 $composeMessage->initAttachment('message/rfc822','email.txt',
52 $full_localfilename);
53 }
54 return $composeMessage;
55 }
56
57
58 /* GLOBALS */
59 $username = $_SESSION['username'];
60 $key = $_COOKIE['key'];
61 $onetimepad = $_SESSION['onetimepad'];
62 $mailbox = $_GET['mailbox'];
63 $passed_id = $_GET['passed_id'];
64 if (isset($_GET['startMessage'])) {
65 $startMessage = $_GET['startMessage'];
66 } else {
67 $startMessage = 1;
68 }
69 if (isset($_GET['passed_ent_id'])) {
70 $passed_ent_id = $_GET['passed_ent_id'];
71 } else {
72 $passed_ent_id = '';
73 }
74 if ( isset($_SESSION['compose_messages']) ) {
75 $compose_messages = &$_SESSION['compose_messages'];
76 }
77
78 if ( isset($_SESSION['composesession']) ) {
79 $composesession = $_SESSION['composesession'];
80 } else {
81 $composesession = 0;
82 sqsession_register($composesession, 'composesession');
83 }
84 /* END GLOBALS */
85
86
87 displayPageHeader($color, $mailbox);
88
89 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
90 $imapPort, 0);
91 sqimap_mailbox_select($imap_stream, $mailbox);
92
93 if ($spamcop_method == 'quick_email' ||
94 $spamcop_method == 'thorough_email') {
95 // Use email-based reporting -- save as an attachment
96 $session = "$composesession"+1;
97 $composesession = $session;
98 sqsession_register($composesession,'composesession');
99 if (!isset($compose_messages)) {
100 $compose_messages = array();
101 }
102 if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)) {
103 $composeMessage = new Message();
104 $rfc822_header = new Rfc822Header();
105 $composeMessage->rfc822_header = $rfc822_header;
106 $composeMessage->reply_rfc822_header = '';
107 $compose_messages[$session] = $composeMessage;
108 sqsession_register($compose_messages,'compose_messages');
109 } else {
110 $composeMessage=$compose_messages[$session];
111 }
112
113
114 $message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
115 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
116 $passed_ent_id='', $imap_stream);
117
118 $compose_messages[$session] = $composeMessage;
119 sqsession_register($compose_messages, 'compose_messages');
120
121 $fn = getPref($data_dir, $username, 'full_name');
122 $em = getPref($data_dir, $username, 'email_address');
123
124 $HowItLooks = $fn . ' ';
125 if ($em != '')
126 $HowItLooks .= '<' . $em . '>';
127 }
128
129 ?>
130
131 <p>Sending this spam report will give you back a reply with URLs that you
132 can click on to properly report this spam message to the proper authorities.
133 This is a free service. By pressing the "Send Spam Report" button, you
134 agree to follow SpamCop's rules/terms of service/etc.</p>
135
136 <table align=center width="75%" border=0 cellpadding=0 cellspacing=0>
137 <tr>
138 <td align=left valign=top>
139 <?PHP if (isset($js_web) && $js_web) {
140 ?><form method=post action="javascript:return false">
141 <input type=button value="Close Window"
142 onClick="window.close(); return true;">
143 <?PHP
144 } else {
145 ?><form method=post action="../../src/right_main.php">
146 <input type=hidden name="mailbox" value="<?PHP echo
147 htmlspecialchars($mailbox) ?>">
148 <input type=hidden name="startMessage" value="<?PHP echo
149 htmlspecialchars($startMessage) ?>">
150 <input type=submit value="Cancel / Done">
151 <?PHP
152 }
153 ?></form>
154 </td>
155 <td align=right valign=top>
156 <?PHP if ($spamcop_method == 'thorough_email' ||
157 $spamcop_method == 'quick_email') {
158 if ($spamcop_method == 'thorough_email')
159 $report_email = 'submit.' . $spamcop_id . '@spam.spamcop.net';
160 else
161 $report_email = 'quick.' . $spamcop_id . '@spam.spamcop.net';
162 $form_action = SM_PATH . 'src/compose.php';
163 ?> <form method=post action="<?PHP echo $form_action?>">
164 <input type=hidden name="mailbox" value="<?PHP echo
165 htmlspecialchars($mailbox) ?>">
166 <input type=hidden name="spamcop_is_composing" value="<?PHP echo
167 htmlspecialchars($passed_id) ?>">
168 <input type=hidden name="send_to" value="<?PHP echo $report_email?>">
169 <input type=hidden name="send_to_cc" value="">
170 <input type=hidden name="send_to_bcc" value="">
171 <input type=hidden name="subject" value="reply anyway">
172 <input type=hidden name="identity" value="default">
173 <input type=hidden name="session" value="<?PHP echo $session?>">
174 <input type=submit name="send" value="Send Spam Report">
175 <?PHP } else {
176 $sid = sqimap_session_id($uid_support);
177 fputs($imap_stream, $sid.' FETCH ' . $passed_id . ' RFC822' . "\r\n");
178
179 $read = sqimap_read_data($imap_stream, $sid, true, $response, $message);
180 array_shift($read);
181
182 $Message = implode('', $read);
183 if (strlen($Message) > 50000) {
184 $Warning = "\n[truncated by SpamCop]\n";
185 $Message = substr($Message, 0, 50000 - strlen($Warning)) . $Warning;
186 }
187 if (isset($js_web) && $js_web) {
188 ?> <form method=post action="http://spamcop.net/sc" name="submitspam"
189 enctype="multipart/form-data"><?PHP
190 } else {
191 ?> <form method=post action="http://spamcop.net/sc" name="submitspam"
192 enctype="multipart/form-data" target="_blank"><?PHP
193 } ?>
194 <input type=hidden name=action value=submit>
195 <input type=hidden name=oldverbose value=1>
196 <input type=hidden name=code value="<?PHP echo $spamcop_id ?>">
197 <input type=hidden name=spam value="<?PHP
198 echo htmlspecialchars($Message);
199 ?>">
200 <input type=submit name="x1" value="Send Spam Report">
201 <?PHP }
202 ?> </form>
203 </td>
204 </tr>
205 </table>
206 </body>
207 </html>