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