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