Adding support for spamcop member service.
[squirrelmail.git] / plugins / spamcop / spamcop.php
CommitLineData
5121598d 1<?php
04f6008a 2 /**
3 ** spamcop.php -- SpamCop plugin
4 **
76911253 5 ** Copyright (c) 1999-2003 The SquirrelMail development team
04f6008a 6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
7 **
ea5f4b8e 8 ** $Id$
9 * @package plugins
10 * @subpackage spamcop
04f6008a 11 **/
5121598d 12
ea5f4b8e 13/** @ignore */
8d6a115b 14define('SM_PATH','../../');
7afb9a75 15
8d6a115b 16 /* SquirrelMail required files. */
17require_once(SM_PATH . 'include/validate.php');
18require_once(SM_PATH . 'functions/imap.php');
04f6008a 19
9a422982 20/**
21 * Stores message in attachment directory, when email based reports are used
22 */
1e89ed41 23function getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
24 $passed_ent_id='', $imapConnection) {
25 global $attachments, $attachment_dir, $username, $data_dir, $uid_support;
9a422982 26
1e89ed41 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 $uid_support);
33 } else {
34 $body_a = sqimap_run_command($imapConnection,
35 'FETCH '.$passed_id.' BODY['.$passed_ent_id.']',
36 TRUE, $response, $readmessage, $uid_support);
37 $message = $message->parent;
38 }
7e449464 39 if ($response == 'OK') {
1e89ed41 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}
04f6008a 62
1e89ed41 63
8ddc4111 64/* GLOBALS */
04f6008a 65
8ddc4111 66sqgetGlobalVar('username', $username, SQ_SESSION);
67sqgetGlobalVar('key', $key, SQ_COOKIE);
68sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
69
70sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
71sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
9a422982 72sqgetGlobalVar('js_web', $js_web, SQ_GET);
8ddc4111 73
74if (! sqgetGlobalVar('startMessage', $startMessage, SQ_GET) ) {
75 $startMessage = 1;
76}
77if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
9a422982 78 $passed_ent_id = 0;
79}
80if (! sqgetGlobalVar('js_web', $js_web, SQ_GET) ) {
81 $js_web = 0;
8ddc4111 82}
83
84sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION);
85
86if(! sqgetGlobalVar('composesession', $composesession, SQ_SESSION) ) {
87 $composesession = 0;
88 sqsession_register($composesession, 'composesession');
89}
90/* END GLOBALS */
1e89ed41 91
9a422982 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.
94if ($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}
5121598d 100
101 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
102 $imapPort, 0);
103 sqimap_mailbox_select($imap_stream, $mailbox);
5121598d 104
105 if ($spamcop_method == 'quick_email' ||
106 $spamcop_method == 'thorough_email') {
107 // Use email-based reporting -- save as an attachment
1e89ed41 108 $session = "$composesession"+1;
109 $composesession = $session;
110 sqsession_register($composesession,'composesession');
111 if (!isset($compose_messages)) {
112 $compose_messages = array();
430be822 113 }
1e89ed41 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];
430be822 123 }
124
04f6008a 125
1e89ed41 126 $message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
127 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
9a422982 128 $passed_ent_id, $imap_stream);
1e89ed41 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 != '')
5121598d 138 $HowItLooks .= '<' . $em . '>';
1e89ed41 139 }
5121598d 140
5121598d 141
2bd52bbe 142echo "<p>";
143echo _("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.");
144echo "</p>";
145
146?>
5121598d 147
8ddc4111 148<table align="center" width="75%" border="0" cellpadding="0" cellspacing="0">
5121598d 149<tr>
8ddc4111 150<td align="left" valign="top">
5121598d 151<?PHP if (isset($js_web) && $js_web) {
8ddc4111 152 ?><form method="post" action="javascript:return false">
153 <input type="button" value="Close Window"
5121598d 154 onClick="window.close(); return true;">
155 <?PHP
156} else {
8ddc4111 157 ?><form method="post" action="../../src/right_main.php">
2bd52bbe 158 <input type="hidden" name="mailbox" value="<?PHP echo htmlspecialchars($mailbox) ?>">
159 <input type="hidden" name="startMessage" value="<?PHP echo htmlspecialchars($startMessage) ?>">
8ddc4111 160 <input type="submit" value="Cancel / Done">
5121598d 161 <?PHP
162}
163 ?></form>
164</td>
8ddc4111 165<td align="right" valign="top">
5121598d 166<?PHP if ($spamcop_method == 'thorough_email' ||
167 $spamcop_method == 'quick_email') {
168 if ($spamcop_method == 'thorough_email')
169 $report_email = 'submit.' . $spamcop_id . '@spam.spamcop.net';
170 else
171 $report_email = 'quick.' . $spamcop_id . '@spam.spamcop.net';
1e89ed41 172 $form_action = SM_PATH . 'src/compose.php';
8ddc4111 173?> <form method="post" action="<?PHP echo $form_action?>">
2bd52bbe 174 <input type="hidden" name="mailbox" value="<?PHP echo htmlspecialchars($mailbox) ?>">
175 <input type="hidden" name="spamcop_is_composing" value="<?PHP echo htmlspecialchars($passed_id) ?>">
8ddc4111 176 <input type="hidden" name="send_to" value="<?PHP echo $report_email?>">
177 <input type="hidden" name="subject" value="reply anyway">
15ac78fe 178 <input type="hidden" name="identity" value="0">
8ddc4111 179 <input type="hidden" name="session" value="<?PHP echo $session?>">
180 <input type="submit" name="send" value="Send Spam Report">
5121598d 181<?PHP } else {
9a422982 182 $spam_message = mime_fetch_body ($imap_stream, $passed_id, $passed_ent_id, 50000);
9538cd4c 183
2b5fddf5 184 if (strlen($spam_message) == 50000) {
5121598d 185 $Warning = "\n[truncated by SpamCop]\n";
2b5fddf5 186 $spam_message = substr($spam_message, 0, 50000 - strlen($Warning)) . $Warning;
5121598d 187 }
9a422982 188 if ($spamcop_type=='member') {
189 $action_url="http://members.spamcop.net/sc";
190 } else {
191 $action_url="http://www.spamcop.net/sc";
192 }
5121598d 193 if (isset($js_web) && $js_web) {
9a422982 194 echo "<form method=\"post\" action=\"$action_url\" name=\"submitspam\"".
195 " enctype=\"multipart/form-data\">\n";
5121598d 196 } else {
9a422982 197 echo "<form method=\"post\" action=\"$action_url\" name=\"submitspam\"".
198 " enctype=\"multipart/form-data\" target=\"_blank\">\n";
5121598d 199 } ?>
8ddc4111 200 <input type="hidden" name="action" value="submit">
201 <input type="hidden" name="oldverbose" value="1">
202 <input type="hidden" name="code" value="<?PHP echo $spamcop_id ?>">
2b5fddf5 203 <input type="hidden" name="spam" value="<?PHP echo htmlspecialchars($spam_message); ?>">
8ddc4111 204 <input type="submit" name="x1" value="Send Spam Report">
5121598d 205<?PHP }
206?> </form>
207</td>
208</tr>
209</table>
dcc1cc82 210 </body>
211</html>