using squirrelmail api for error message
[squirrelmail.git] / plugins / spamcop / spamcop.php
1 <?php
2 /**
3 * spamcop.php -- SpamCop plugin -- main page
4 *
5 * @copyright (c) 1999-2005 The SquirrelMail Project 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 $attachment_dir, $username;
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 array_shift($body_a);
41 $body = implode('', $body_a) . "\r\n";
42
43 $localfilename = GenerateRandomString(32, 'FILE', 7);
44 $full_localfilename = "$hashed_attachment_dir/$localfilename";
45 $fp = fopen( $full_localfilename, 'w');
46 fwrite ($fp, $body);
47 fclose($fp);
48
49 /* dirty relative dir fix */
50 if (substr($attachment_dir,0,3) == '../') {
51 $attachment_dir = substr($attachment_dir,3);
52 $hashed_attachment_dir = getHashedDir($username, $attachment_dir);
53 }
54 $full_localfilename = "$hashed_attachment_dir/$localfilename";
55
56 $composeMessage->initAttachment('message/rfc822','email.txt',
57 $full_localfilename);
58 }
59 return $composeMessage;
60 }
61
62
63 /* GLOBALS */
64
65 sqgetGlobalVar('username', $username, SQ_SESSION);
66 sqgetGlobalVar('key', $key, SQ_COOKIE);
67 sqgetGlobalVar('onetimepad', $onetimepad, SQ_SESSION);
68
69 sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
70 sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
71 sqgetGlobalVar('js_web', $js_web, SQ_GET);
72
73 if (! sqgetGlobalVar('startMessage', $startMessage, SQ_GET) ) {
74 $startMessage = 1;
75 }
76 if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
77 $passed_ent_id = 0;
78 }
79 if (! sqgetGlobalVar('js_web', $js_web, SQ_GET) ) {
80 $js_web = 0;
81 }
82
83 sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION);
84
85 if(! sqgetGlobalVar('composesession', $composesession, SQ_SESSION) ) {
86 $composesession = 0;
87 sqsession_register($composesession, 'composesession');
88 }
89 /* END GLOBALS */
90
91 // js_web variable is 1 only when link opens web based report page in new window
92 // and in new window menu line or extra javascript code is not needed.
93 if ($js_web) {
94 displayHTMLHeader(_("SpamCop reporting"));
95 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n";
96 } else {
97 displayPageHeader($color,$mailbox);
98 }
99
100 $imap_stream = sqimap_login($username, $key, $imapServerAddress,
101 $imapPort, 0);
102 sqimap_mailbox_select($imap_stream, $mailbox);
103
104 if ($spamcop_method == 'quick_email' ||
105 $spamcop_method == 'thorough_email') {
106 // Use email-based reporting -- save as an attachment
107 $session = "$composesession"+1;
108 $composesession = $session;
109 sqsession_register($composesession,'composesession');
110 if (!isset($compose_messages)) {
111 $compose_messages = array();
112 }
113 if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)) {
114 $composeMessage = new Message();
115 $rfc822_header = new Rfc822Header();
116 $composeMessage->rfc822_header = $rfc822_header;
117 $composeMessage->reply_rfc822_header = '';
118 $compose_messages[$session] = $composeMessage;
119 sqsession_register($compose_messages,'compose_messages');
120 } else {
121 $composeMessage=$compose_messages[$session];
122 }
123
124
125 $message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
126 $composeMessage = getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
127 $passed_ent_id, $imap_stream);
128
129 $compose_messages[$session] = $composeMessage;
130 sqsession_register($compose_messages, 'compose_messages');
131
132 $fn = getPref($data_dir, $username, 'full_name');
133 $em = getPref($data_dir, $username, 'email_address');
134
135 $HowItLooks = $fn . ' ';
136 if ($em != '')
137 $HowItLooks .= '<' . $em . '>';
138 }
139
140
141 echo "<p>";
142 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.");
143 echo "</p>";
144
145 ?>
146
147 <table align="center" width="75%" border="0" cellpadding="0" cellspacing="0">
148 <tr>
149 <td align="left" valign="top">
150 <?php if (isset($js_web) && $js_web) {
151 echo '<form method="post" action="javascript:return false">';
152 echo '<input type="button" value="' . _("Close Window") . "\" onclick=\"window.close(); return true;\" />\n";
153 } else {
154 ?><form method="post" action="../../src/right_main.php">
155 <input type="hidden" name="mailbox" value="<?php echo htmlspecialchars($mailbox) ?>" />
156 <input type="hidden" name="startMessage" value="<?php echo htmlspecialchars($startMessage) ?>" />
157 <?php
158 echo '<input type="submit" value="' . _("Cancel / Done") . "\" />";
159 }
160 ?></form>
161 </td>
162 <td align="right" valign="top">
163 <?php if ($spamcop_method == 'thorough_email' ||
164 $spamcop_method == 'quick_email') {
165 if ($spamcop_method == 'thorough_email')
166 $report_email = 'submit.' . $spamcop_id . '@spam.spamcop.net';
167 else
168 $report_email = 'quick.' . $spamcop_id . '@spam.spamcop.net';
169 $form_action = SM_PATH . 'src/compose.php';
170 ?> <form method="post" action="<?php echo $form_action?>">
171 <input type="hidden" name="mailbox" value="<?php echo htmlspecialchars($mailbox) ?>" />
172 <input type="hidden" name="spamcop_is_composing" value="<?php echo htmlspecialchars($passed_id) ?>" />
173 <input type="hidden" name="send_to" value="<?php echo htmlspecialchars($report_email)?>" />
174 <input type="hidden" name="subject" value="reply anyway" />
175 <input type="hidden" name="identity" value="0" />
176 <input type="hidden" name="session" value="<?php echo $session?>" />
177 <?php
178 echo '<input type="submit" name="send" value="' . _("Send Spam Report") . "\" />\n";
179 } else {
180 $spam_message = mime_fetch_body ($imap_stream, $passed_id, $passed_ent_id, 50000);
181
182 if (strlen($spam_message) == 50000) {
183 $Warning = "\n[truncated by SpamCop]\n";
184 $spam_message = substr($spam_message, 0, 50000 - strlen($Warning)) . $Warning;
185 }
186 if ($spamcop_type=='member') {
187 $action_url="http://members.spamcop.net/sc";
188 } else {
189 $action_url="http://www.spamcop.net/sc";
190 }
191 if (isset($js_web) && $js_web) {
192 echo "<form method=\"post\" action=\"$action_url\" name=\"submitspam\"".
193 " enctype=\"multipart/form-data\">\n";
194 } else {
195 echo "<form method=\"post\" action=\"$action_url\" name=\"submitspam\"".
196 " enctype=\"multipart/form-data\" target=\"_blank\">\n";
197 } ?>
198 <input type="hidden" name="action" value="submit" />
199 <input type="hidden" name="oldverbose" value="1" />
200 <input type="hidden" name="code" value="<?php echo htmlspecialchars($spamcop_id) ?>" />
201 <input type="hidden" name="spam" value="<?php echo htmlspecialchars($spam_message); ?>" />
202 <?php
203 echo '<input type="submit" name="x1" value="' . _("Send Spam Report") . "\" />\n";
204 }
205 ?> </form>
206 </td>
207 </tr>
208 </table>
209 </body>
210 </html>