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