handle DB.php load errors inside preference class and don't worry about
[squirrelmail.git] / plugins / spamcop / spamcop.php
CommitLineData
5121598d 1<?php
4b4abf93 2
91e0dccc 3/**
f3a91d6b 4 * spamcop.php -- SpamCop plugin -- main page
5 *
47ccfad4 6 * @copyright &copy; 1999-2006 The SquirrelMail Project Team
f3a91d6b 7 * @license http://opensource.org/licenses/gpl-license.php GNU Public License
8 * @version $Id$
9 * @package plugins
10 * @subpackage spamcop
11 */
5121598d 12
202bcbcc 13/**
14 * Include the SquirrelMail initialization file.
15 */
16require('../../include/init.php');
7afb9a75 17
202bcbcc 18include_once(SM_PATH . 'functions/imap_general.php');
19include_once(SM_PATH . 'functions/imap_messages.php');
da297dd0 20/* plugin functions */
21include_once(SM_PATH . 'plugins/spamcop/functions.php');
1e89ed41 22
8ddc4111 23/* GLOBALS */
04f6008a 24
8ddc4111 25sqgetGlobalVar('username', $username, SQ_SESSION);
8ddc4111 26
27sqgetGlobalVar('mailbox', $mailbox, SQ_GET);
28sqgetGlobalVar('passed_id', $passed_id, SQ_GET);
9a422982 29sqgetGlobalVar('js_web', $js_web, SQ_GET);
8ddc4111 30
31if (! sqgetGlobalVar('startMessage', $startMessage, SQ_GET) ) {
32 $startMessage = 1;
33}
34if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_GET) ) {
9a422982 35 $passed_ent_id = 0;
36}
37if (! sqgetGlobalVar('js_web', $js_web, SQ_GET) ) {
38 $js_web = 0;
8ddc4111 39}
40
41sqgetGlobalVar('compose_messages', $compose_messages, SQ_SESSION);
42
43if(! sqgetGlobalVar('composesession', $composesession, SQ_SESSION) ) {
44 $composesession = 0;
45 sqsession_register($composesession, 'composesession');
46}
47/* END GLOBALS */
1e89ed41 48
9a422982 49// js_web variable is 1 only when link opens web based report page in new window
50// and in new window menu line or extra javascript code is not needed.
51if ($js_web) {
7d56f214 52 displayHTMLHeader(_("SpamCop reporting"));
9a422982 53 echo "<body text=\"$color[8]\" bgcolor=\"$color[4]\" link=\"$color[7]\" vlink=\"$color[7]\" alink=\"$color[7]\">\n";
54} else {
55 displayPageHeader($color,$mailbox);
56}
5121598d 57
da297dd0 58/** is spamcop plugin disabled */
59if (! is_plugin_enabled('spamcop')) {
60 error_box(_("Plugin is disabled."),$color);
61 echo "\n</body></html>\n";
62 exit();
63}
64
045ec1a1 65 $imap_stream = sqimap_login($username, false, $imapServerAddress, $imapPort, 0);
5121598d 66 sqimap_mailbox_select($imap_stream, $mailbox);
5121598d 67
91e0dccc 68 if ($spamcop_method == 'quick_email' ||
5121598d 69 $spamcop_method == 'thorough_email') {
70 // Use email-based reporting -- save as an attachment
1e89ed41 71 $session = "$composesession"+1;
72 $composesession = $session;
73 sqsession_register($composesession,'composesession');
74 if (!isset($compose_messages)) {
75 $compose_messages = array();
430be822 76 }
1e89ed41 77 if (!isset($compose_messages[$session]) || ($compose_messages[$session] == NULL)) {
78 $composeMessage = new Message();
79 $rfc822_header = new Rfc822Header();
80 $composeMessage->rfc822_header = $rfc822_header;
81 $composeMessage->reply_rfc822_header = '';
82 $compose_messages[$session] = $composeMessage;
91e0dccc 83 sqsession_register($compose_messages,'compose_messages');
1e89ed41 84 } else {
85 $composeMessage=$compose_messages[$session];
430be822 86 }
87
04f6008a 88
1e89ed41 89 $message = sqimap_get_message($imap_stream, $passed_id, $mailbox);
2b42190d 90 $composeMessage = spamcop_getMessage_RFC822_Attachment($message, $composeMessage, $passed_id,
9a422982 91 $passed_ent_id, $imap_stream);
1e89ed41 92
91e0dccc 93 $compose_messages[$session] = $composeMessage;
94 sqsession_register($compose_messages, 'compose_messages');
1e89ed41 95
96 $fn = getPref($data_dir, $username, 'full_name');
97 $em = getPref($data_dir, $username, 'email_address');
98
99 $HowItLooks = $fn . ' ';
100 if ($em != '')
5121598d 101 $HowItLooks .= '<' . $em . '>';
1e89ed41 102 }
5121598d 103
5121598d 104
2bd52bbe 105echo "<p>";
99aaff8b 106echo _("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 107echo "</p>";
108
109?>
5121598d 110
8ddc4111 111<table align="center" width="75%" border="0" cellpadding="0" cellspacing="0">
5121598d 112<tr>
8ddc4111 113<td align="left" valign="top">
6fd95361 114<?php if (isset($js_web) && $js_web) {
7d56f214 115 echo '<form method="post" action="javascript:return false">';
c435f076 116 echo '<input type="button" value="' . _("Close Window") . "\" onclick=\"window.close(); return true;\" />\n";
5121598d 117} else {
8ddc4111 118 ?><form method="post" action="../../src/right_main.php">
6fd95361 119 <input type="hidden" name="mailbox" value="<?php echo htmlspecialchars($mailbox) ?>" />
120 <input type="hidden" name="startMessage" value="<?php echo htmlspecialchars($startMessage) ?>" />
121<?php
7d56f214 122 echo '<input type="submit" value="' . _("Cancel / Done") . "\" />";
5121598d 123}
124 ?></form>
125</td>
8ddc4111 126<td align="right" valign="top">
6fd95361 127<?php if ($spamcop_method == 'thorough_email' ||
5121598d 128 $spamcop_method == 'quick_email') {
129 if ($spamcop_method == 'thorough_email')
130 $report_email = 'submit.' . $spamcop_id . '@spam.spamcop.net';
131 else
132 $report_email = 'quick.' . $spamcop_id . '@spam.spamcop.net';
1e89ed41 133 $form_action = SM_PATH . 'src/compose.php';
6fd95361 134?> <form method="post" action="<?php echo $form_action?>">
135 <input type="hidden" name="mailbox" value="<?php echo htmlspecialchars($mailbox) ?>" />
136 <input type="hidden" name="spamcop_is_composing" value="<?php echo htmlspecialchars($passed_id) ?>" />
137 <input type="hidden" name="send_to" value="<?php echo htmlspecialchars($report_email)?>" />
7d56f214 138 <input type="hidden" name="subject" value="reply anyway" />
139 <input type="hidden" name="identity" value="0" />
6fd95361 140 <input type="hidden" name="session" value="<?php echo $session?>" />
7d56f214 141<?php
142 echo '<input type="submit" name="send" value="' . _("Send Spam Report") . "\" />\n";
143} else {
9a422982 144 $spam_message = mime_fetch_body ($imap_stream, $passed_id, $passed_ent_id, 50000);
9538cd4c 145
2b5fddf5 146 if (strlen($spam_message) == 50000) {
5121598d 147 $Warning = "\n[truncated by SpamCop]\n";
2b5fddf5 148 $spam_message = substr($spam_message, 0, 50000 - strlen($Warning)) . $Warning;
5121598d 149 }
9a422982 150 if ($spamcop_type=='member') {
151 $action_url="http://members.spamcop.net/sc";
152 } else {
153 $action_url="http://www.spamcop.net/sc";
154 }
5121598d 155 if (isset($js_web) && $js_web) {
9a422982 156 echo "<form method=\"post\" action=\"$action_url\" name=\"submitspam\"".
157 " enctype=\"multipart/form-data\">\n";
5121598d 158 } else {
9a422982 159 echo "<form method=\"post\" action=\"$action_url\" name=\"submitspam\"".
160 " enctype=\"multipart/form-data\" target=\"_blank\">\n";
5121598d 161 } ?>
7d56f214 162 <input type="hidden" name="action" value="submit" />
163 <input type="hidden" name="oldverbose" value="1" />
6fd95361 164 <input type="hidden" name="code" value="<?php echo htmlspecialchars($spamcop_id) ?>" />
165 <input type="hidden" name="spam" value="<?php echo htmlspecialchars($spam_message); ?>" />
7d56f214 166 <?php
91e0dccc 167 echo '<input type="submit" name="x1" value="' . _("Send Spam Report") . "\" />\n";
7d56f214 168 }
5121598d 169?> </form>
170</td>
171</tr>
172</table>
7d56f214 173</body>
91e0dccc 174</html>