772be735 |
1 | <?php |
91e0dccc |
2 | /** |
f3a91d6b |
3 | * setup.php -- SpamCop plugin - setup script |
4 | * |
6c84ba1e |
5 | * @copyright (c) 1999-2005 The SquirrelMail development team |
f3a91d6b |
6 | * @license http://opensource.org/licenses/gpl-license.php GNU Public License |
7 | * @version $Id$ |
8 | * @package plugins |
9 | * @subpackage spamcop |
10 | */ |
772be735 |
11 | |
ea5f4b8e |
12 | /** @ignore */ |
0dabfa7f |
13 | require_once(SM_PATH . 'functions/global.php'); |
14 | |
057e9d6e |
15 | /** Disable Quick Reporting by default */ |
16 | $spamcop_quick_report = false; |
0dabfa7f |
17 | |
f3a91d6b |
18 | /** |
91e0dccc |
19 | * Initialize the plugin |
f3a91d6b |
20 | * @access private |
21 | */ |
772be735 |
22 | function squirrelmail_plugin_init_spamcop() { |
91e0dccc |
23 | global $squirrelmail_plugin_hooks, $spamcop_is_composing; |
772be735 |
24 | |
91e0dccc |
25 | $squirrelmail_plugin_hooks['optpage_register_block']['spamcop'] = |
26 | 'spamcop_options'; |
27 | $squirrelmail_plugin_hooks['loading_prefs']['spamcop'] = |
28 | 'spamcop_load'; |
29 | $squirrelmail_plugin_hooks['read_body_header_right']['spamcop'] = |
30 | 'spamcop_show_link'; |
04f6008a |
31 | |
3267e4d8 |
32 | sqgetGlobalVar('spamcop_is_composing' , $spamcop_is_composing); |
91e0dccc |
33 | |
34 | if (isset($spamcop_is_composing)) { |
35 | $squirrelmail_plugin_hooks['compose_send']['spamcop'] = |
36 | 'spamcop_while_sending'; |
37 | } |
772be735 |
38 | } |
39 | |
40 | |
9a422982 |
41 | /** |
42 | * Loads spamcop settings and validates some of values (make '' into 'default', etc.) |
f3a91d6b |
43 | * @access private |
9a422982 |
44 | */ |
772be735 |
45 | function spamcop_load() { |
91e0dccc |
46 | global $username, $data_dir, $spamcop_enabled, $spamcop_delete, |
47 | $spamcop_method, $spamcop_id, $spamcop_quick_report, $spamcop_type; |
48 | |
49 | $spamcop_enabled = getPref($data_dir, $username, 'spamcop_enabled'); |
50 | $spamcop_delete = getPref($data_dir, $username, 'spamcop_delete'); |
51 | $spamcop_method = getPref($data_dir, $username, 'spamcop_method'); |
52 | $spamcop_type = getPref($data_dir, $username, 'spamcop_type'); |
53 | $spamcop_id = getPref($data_dir, $username, 'spamcop_id'); |
057e9d6e |
54 | if ($spamcop_method == '') { |
91e0dccc |
55 | // Default to web_form. It is faster. |
56 | $spamcop_method = 'web_form'; |
57 | setPref($data_dir, $username, 'spamcop_method', $spamcop_method); |
58 | } |
59 | if (! $spamcop_quick_report && $spamcop_method=='quick_email') { |
60 | $spamcop_method = 'web_form'; |
61 | setPref($data_dir, $username, 'spamcop_method', $spamcop_method); |
057e9d6e |
62 | } |
91e0dccc |
63 | if ($spamcop_type == '') { |
64 | $spamcop_type = 'free'; |
65 | setPref($data_dir, $username, 'spamcop_type', $spamcop_type); |
66 | } |
67 | if ($spamcop_id == '') |
68 | $spamcop_enabled = 0; |
772be735 |
69 | } |
70 | |
71 | |
9a422982 |
72 | /** |
73 | * Shows spamcop link on the read-a-message screen |
f3a91d6b |
74 | * @access private |
9a422982 |
75 | */ |
772be735 |
76 | function spamcop_show_link() { |
91e0dccc |
77 | global $spamcop_enabled, $spamcop_method, $spamcop_quick_report,$javascript_on; |
772be735 |
78 | |
91e0dccc |
79 | if (! $spamcop_enabled) |
80 | return; |
772be735 |
81 | |
91e0dccc |
82 | /* GLOBALS */ |
83 | sqgetGlobalVar('passed_id', $passed_id, SQ_FORM); |
84 | sqgetGlobalVar('passed_ent_id',$passed_ent_id,SQ_FORM); |
85 | sqgetGlobalVar('mailbox', $mailbox, SQ_FORM); |
86 | sqgetGlobalVar('startMessage', $startMessage, SQ_FORM); |
87 | /* END GLOBALS */ |
04f6008a |
88 | |
91e0dccc |
89 | // catch unset passed_ent_id |
90 | if (! sqgetGlobalVar('passed_ent_id', $passed_ent_id, SQ_FORM) ) { |
91 | $passed_ent_id = 0; |
92 | } |
9a422982 |
93 | |
91e0dccc |
94 | echo "<br />\n"; |
057e9d6e |
95 | |
91e0dccc |
96 | /* |
97 | Catch situation when user use quick_email and does not update |
98 | preferences. User gets web_form link. If prefs are set to |
057e9d6e |
99 | quick_email format - they will be updated after clicking the link |
100 | */ |
101 | if (! $spamcop_quick_report && $spamcop_method=='quick_email') { |
91e0dccc |
102 | $spamcop_method = 'web_form'; |
057e9d6e |
103 | } |
91e0dccc |
104 | |
9a422982 |
105 | // Javascript is used only in web based reporting |
106 | // don't insert javascript if javascript is disabled |
91e0dccc |
107 | if ($spamcop_method == 'web_form' && $javascript_on) { |
8ddc4111 |
108 | ?><script language="javascript" type="text/javascript"> |
6fd95361 |
109 | document.write('<a href="../plugins/spamcop/spamcop.php?passed_id=<?php echo urlencode($passed_id); ?>&js_web=1&mailbox=<?php echo urlencode($mailbox); ?>&passed_ent_id=<?php echo urlencode($passed_ent_id); ?>" target="_blank">'); |
110 | document.write("<?php echo _("Report as Spam"); ?>"); |
772be735 |
111 | document.write("</a>"); |
6fd95361 |
112 | </script><?php |
91e0dccc |
113 | } else { |
6fd95361 |
114 | ?><a href="../plugins/spamcop/spamcop.php?passed_id=<?php echo urlencode($passed_id); ?>&mailbox=<?php echo urlencode($mailbox); ?>&startMessage=<?php echo urlencode($startMessage); ?>&passed_ent_id=<?php echo urlencode($passed_ent_id); ?>"> |
115 | <?php echo _("Report as Spam"); ?></a> |
116 | <?php |
91e0dccc |
117 | } |
772be735 |
118 | } |
119 | |
9a422982 |
120 | /** |
121 | * Show spamcop options block |
f3a91d6b |
122 | * @access private |
9a422982 |
123 | */ |
772be735 |
124 | function spamcop_options() |
125 | { |
91e0dccc |
126 | global $optpage_blocks; |
127 | |
128 | $optpage_blocks[] = array( |
129 | 'name' => _("SpamCop - Spam Reporting"), |
130 | 'url' => '../plugins/spamcop/options.php', |
131 | 'desc' => _("Help fight the battle against unsolicited email. SpamCop reads the spam email and determines the correct addresses to send complaints to. Quite fast, really smart, and easy to use."), |
132 | 'js' => false |
133 | ); |
772be735 |
134 | } |
135 | |
136 | |
9a422982 |
137 | /** |
138 | * When we send the email, we optionally trash it then too |
f3a91d6b |
139 | * @access private |
9a422982 |
140 | */ |
772be735 |
141 | function spamcop_while_sending() |
142 | { |
91e0dccc |
143 | global $mailbox, $spamcop_delete, $spamcop_is_composing, $auto_expunge, |
144 | $username, $key, $imapServerAddress, $imapPort; |
145 | |
146 | if ($spamcop_delete) { |
147 | $imapConnection = sqimap_login($username, $key, $imapServerAddress, |
148 | $imapPort, 0); |
149 | sqimap_mailbox_select($imapConnection, $mailbox); |
150 | sqimap_messages_delete($imapConnection, $spamcop_is_composing, |
151 | $spamcop_is_composing, $mailbox); |
152 | if ($auto_expunge) |
153 | sqimap_mailbox_expunge($imapConnection, $mailbox, true); |
154 | } |
772be735 |
155 | } |
156 | |
057e9d6e |
157 | ?> |