I18n fixes
[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) {
6201339c 25 global $attachments, $attachment_dir, $username, $data_dir;
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 $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) {
7d56f214 95 displayHTMLHeader(_("SpamCop reporting"));
9a422982 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>";
99aaff8b 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.");
2bd52bbe 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) {
7d56f214 152 echo '<form method="post" action="javascript:return false">';
153 echo '<input type="button" value="' . _("Close Window") . "\" onClick=\"window.close(); return true;\" />\n";
5121598d 154} else {
8ddc4111 155 ?><form method="post" action="../../src/right_main.php">
7d56f214 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") . "\" />";
5121598d 160}
161 ?></form>
162</td>
8ddc4111 163<td align="right" valign="top">
5121598d 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';
1e89ed41 170 $form_action = SM_PATH . 'src/compose.php';
8ddc4111 171?> <form method="post" action="<?PHP echo $form_action?>">
7d56f214 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) ?>" />
a9e1e670 174 <input type="hidden" name="send_to" value="<?PHP echo htmlspecialchars($report_email)?>" />
7d56f214 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 {
9a422982 181 $spam_message = mime_fetch_body ($imap_stream, $passed_id, $passed_ent_id, 50000);
9538cd4c 182
2b5fddf5 183 if (strlen($spam_message) == 50000) {
5121598d 184 $Warning = "\n[truncated by SpamCop]\n";
2b5fddf5 185 $spam_message = substr($spam_message, 0, 50000 - strlen($Warning)) . $Warning;
5121598d 186 }
9a422982 187 if ($spamcop_type=='member') {
188 $action_url="http://members.spamcop.net/sc";
189 } else {
190 $action_url="http://www.spamcop.net/sc";
191 }
5121598d 192 if (isset($js_web) && $js_web) {
9a422982 193 echo "<form method=\"post\" action=\"$action_url\" name=\"submitspam\"".
194 " enctype=\"multipart/form-data\">\n";
5121598d 195 } else {
9a422982 196 echo "<form method=\"post\" action=\"$action_url\" name=\"submitspam\"".
197 " enctype=\"multipart/form-data\" target=\"_blank\">\n";
5121598d 198 } ?>
7d56f214 199 <input type="hidden" name="action" value="submit" />
200 <input type="hidden" name="oldverbose" value="1" />
a9e1e670 201 <input type="hidden" name="code" value="<?PHP echo htmlspecialchars($spamcop_id) ?>" />
7d56f214 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 }
5121598d 206?> </form>
207</td>
208</tr>
209</table>
7d56f214 210</body>
dcc1cc82 211</html>