e8b140ab |
1 | <?php |
2 | |
08185f2a |
3 | /* Path for SquirrelMail required files. */ |
4 | define('SM_PATH','../../'); |
d55c0f66 |
5 | |
08185f2a |
6 | /* SquirrelMail required files. */ |
7 | require_once(SM_PATH . 'functions/url_parser.php'); |
e8b140ab |
8 | |
9 | /* Address Take -- steals addresses from incoming email messages. Searches |
10 | the To, Cc, From and Reply-To headers, also searches the body of the |
11 | message. */ |
12 | |
13 | function squirrelmail_plugin_init_abook_take() |
14 | { |
15 | global $squirrelmail_plugin_hooks; |
16 | |
17 | $squirrelmail_plugin_hooks['read_body_bottom']['abook_take'] = 'abook_take_read'; |
18 | $squirrelmail_plugin_hooks['loading_prefs']['abook_take'] = 'abook_take_pref'; |
19 | $squirrelmail_plugin_hooks['options_display_inside']['abook_take'] = 'abook_take_options'; |
20 | $squirrelmail_plugin_hooks['options_display_save']['abook_take'] = 'abook_take_save'; |
21 | } |
22 | |
23 | |
24 | function valid_email ($email, $verify) |
25 | { |
d55c0f66 |
26 | global $abook_take_verify, $Email_RegExp_Match; |
e8b140ab |
27 | |
d55c0f66 |
28 | if (! eregi('^' . $Email_RegExp_Match . '$', $email)) |
29 | return false; |
e8b140ab |
30 | |
d55c0f66 |
31 | if (! $verify) |
32 | return true; |
33 | |
34 | if (! checkdnsrr(substr(strstr($email, '@'), 1), 'ANY')) |
35 | return false; |
36 | |
37 | return true; |
e8b140ab |
38 | } |
39 | |
40 | |
41 | function abook_take_read_string($str) |
42 | { |
d55c0f66 |
43 | global $abook_found_email, $Email_RegExp_Match; |
e8b140ab |
44 | |
d55c0f66 |
45 | |
46 | while (eregi('(' . $Email_RegExp_Match . ')', $str, $hits)) |
e8b140ab |
47 | { |
d55c0f66 |
48 | $str = substr(strstr($str, $hits[0]), strlen($hits[0])); |
49 | if (! isset($abook_found_email[$hits[0]])) |
50 | { |
51 | echo "<input type=\"hidden\" name=\"email[]\" value=\"$hits[0]\">\n"; |
52 | $abook_found_email[$hits[0]] = 1; |
53 | } |
e8b140ab |
54 | } |
d55c0f66 |
55 | return; |
e8b140ab |
56 | } |
57 | |
58 | |
59 | function abook_take_read_array($array) |
60 | { |
61 | $i = 0; |
62 | while ($i < count($array)) |
63 | { |
673f9350 |
64 | abook_take_read_string($array[$i]->getAddress()); |
e8b140ab |
65 | $i ++; |
66 | } |
67 | } |
68 | |
69 | |
70 | function abook_take_read() |
71 | { |
72 | global $color, $abook_take_location; |
73 | global $body, $abook_take_hide, $message, $imapConnection; |
74 | |
75 | if ($abook_take_hide) |
76 | return; |
77 | |
4cf43843 |
78 | echo '<form action="../plugins/abook_take/take.php" method="post">' . "\n" . |
79 | html_tag( 'table', '', $abook_take_location, $color[10], 'cellpadding="3" cellspacing="0" border="0"' ) . |
80 | html_tag( 'tr' ) . |
81 | html_tag( 'td', '', 'left' ) . |
82 | html_tag( 'table', '', '', $color[5], 'cellpadding="2" cellspacing="1" border="0"' ) . |
83 | html_tag( 'tr' ) . |
84 | html_tag( 'td' ); |
85 | |
673f9350 |
86 | if (isset($message->rfc822_header->from)) |
87 | abook_take_read_array($message->rfc822_header->from); |
88 | if (isset($message->rfc822_header->cc)) |
89 | abook_take_read_array($message->rfc822_header->cc); |
90 | if (isset($message->rfc822_header->reply_to)) |
91 | abook_take_read_array($message->rfc822_header->reply_to); |
92 | if (isset($message->rfc822_header->to)) |
93 | abook_take_read_array($message->rfc822_header->to); |
e8b140ab |
94 | |
95 | |
96 | $new_body = $body; |
97 | $pos = strpos($new_body, |
4cf43843 |
98 | '">' . _("Download this as a file") . '</a></center><br></small>'); |
e8b140ab |
99 | if (is_int($pos)) |
100 | { |
101 | $new_body = substr($new_body, 0, $pos); |
102 | } |
103 | |
104 | $trans = get_html_translation_table(HTML_ENTITIES); |
105 | $trans[' '] = ' '; |
106 | $trans = array_flip($trans); |
107 | $new_body = strtr($new_body, $trans); |
108 | |
109 | $new_body = urldecode($new_body); |
110 | $new_body = strip_tags($new_body); |
111 | |
112 | $new_body = strtr($new_body, "\n", ' '); |
113 | |
114 | abook_take_read_string($body); |
4cf43843 |
115 | |
116 | echo '<input type="submit" value="' . _("Take Address") . '">'; |
e8b140ab |
117 | ?> |
e8b140ab |
118 | </td> |
119 | </tr> |
120 | </table> |
121 | </td> |
122 | </tr> |
123 | </table> |
124 | </form> |
125 | <?PHP |
126 | } |
127 | |
128 | function abook_take_pref() |
129 | { |
130 | global $username, $data_dir; |
131 | global $abook_take_hide, $abook_take_location, $abook_take_verify; |
132 | |
133 | $abook_take_location = getPref($data_dir, $username, 'abook_take_location'); |
134 | if ($abook_take_location == '') |
135 | $abook_take_location = 'center'; |
136 | |
137 | $abook_take_hide = getPref($data_dir, $username, 'abook_take_hide'); |
138 | $abook_take_verify = getPref($data_dir, $username, 'abook_take_verify'); |
139 | } |
140 | |
141 | |
142 | function abook_take_options() |
143 | { |
144 | global $abook_take_location, $abook_take_hide, $abook_take_verify; |
145 | |
4cf43843 |
146 | echo html_tag( 'tr' ) . |
147 | html_tag( 'td', _("Address Book Take") . ':', 'right', '', 'nowrap valign="top"' ) . |
148 | html_tag( 'td', '', 'left' ) . |
149 | '<select name="abook_take_abook_take_location">' . |
150 | '<option value="left"'; |
151 | if ($abook_take_location == 'left') |
152 | echo ' selected'; |
153 | echo '>' . _("Left aligned") . '</option>' . |
154 | '<option value="center"'; |
155 | if ($abook_take_location == 'center') |
156 | echo ' selected'; |
157 | echo '>' . _("Centered") . '</option>' . |
158 | '<option value="right"'; |
159 | if ($abook_take_location == 'right') |
160 | echo ' selected'; |
161 | echo '>' . _("Right aligned") . '</option>' . |
162 | '</select> ' . _("on the Read screen") .'<br>' . |
163 | '<input type="checkbox" name="abook_take_abook_take_hide"'; |
164 | if ($abook_take_hide) |
165 | echo ' checked'; |
2798d757 |
166 | echo '> ' . _("Hide the box") . '<br>' . |
4cf43843 |
167 | '<input type=checkbox name="abook_take_abook_take_verify"'; |
168 | if ($abook_take_verify) |
169 | echo ' checked'; |
2798d757 |
170 | echo '> ' . _("Try to verify addresses") . '</td></tr>'; |
e8b140ab |
171 | } |
172 | |
173 | |
174 | function abook_take_save() |
175 | { |
176 | global $username, $data_dir; |
177 | global $abook_take_abook_take_location; |
178 | global $abook_take_abook_take_hide; |
179 | global $abook_take_abook_take_verify; |
180 | |
181 | |
182 | if (isset($abook_take_abook_take_location)) |
183 | { |
184 | setPref($data_dir, $username, 'abook_take_location', $abook_take_abook_take_location); |
185 | } |
186 | else |
187 | { |
188 | setPref($data_dir, $username, 'abook_take_location', 'center'); |
189 | } |
190 | |
191 | if (isset($abook_take_abook_take_hide)) |
192 | { |
193 | setPref($data_dir, $username, 'abook_take_hide', '1'); |
194 | } |
195 | else |
196 | { |
197 | setPref($data_dir, $username, 'abook_take_hide', ''); |
198 | } |
199 | |
200 | if (isset($abook_take_abook_take_verify)) |
201 | { |
202 | setPref($data_dir, $username, 'abook_take_verify', '1'); |
203 | } |
204 | else |
205 | { |
206 | setPref($data_dir, $username, 'abook_take_verify', ''); |
207 | } |
208 | } |
209 | |
210 | ?> |