upgraded to version 1.4 and debugged
[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 ?>
76 <FORM ACTION="../plugins/abook_take/take.php" METHOD=POST>
77 <table align="<?PHP
78 echo $abook_take_location;
79 ?>" cellpadding=3 cellspacing=0 border=0 bgcolor="<?PHP
80 echo $color[10]
81 ?>">
82 <tr>
83 <td>
84 <table cellpadding=2 cellspacing=1 border=0 bgcolor="<?PHP
85 echo $color[5]
86 ?>">
87 <tr>
88 <td>
89 <?PHP
90 abook_take_read_string($message->header->from);
91 abook_take_read_array($message->header->cc);
92 abook_take_read_array($message->header->reply_to);
93 abook_take_read_array($message->header->to);
94
95
96 $new_body = $body;
97 $pos = strpos($new_body,
98 '">Download this as a file</A></CENTER><BR></SMALL>');
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[' '] = '&nbsp;';
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);
115 ?>
116 <INPUT TYPE="submit" VALUE="Take Address">
117 </td>
118 </tr>
119 </table>
120 </td>
121 </tr>
122 </table>
123 </form>
124 <?PHP
125 }
126
127 function abook_take_pref()
128 {
129 global $username, $data_dir;
130 global $abook_take_hide, $abook_take_location, $abook_take_verify;
131
132 $abook_take_location = getPref($data_dir, $username, 'abook_take_location');
133 if ($abook_take_location == '')
134 $abook_take_location = 'center';
135
136 $abook_take_hide = getPref($data_dir, $username, 'abook_take_hide');
137 $abook_take_verify = getPref($data_dir, $username, 'abook_take_verify');
138 }
139
140
141 function abook_take_options()
142 {
143 global $abook_take_location, $abook_take_hide, $abook_take_verify;
144
145 ?><tr><td align=right nowrap valign="top">Address Book Take:</td>
146 <td><select name="abook_take_abook_take_location">
147 <option value="left"<?PHP
148 if ($abook_take_location == 'left')
149 echo ' SELECTED';
150 ?>>Left aligned</option>
151 <option value="center"<?PHP
152 if ($abook_take_location == 'center')
153 echo ' SELECTED';
154 ?>>Centered</option>
155 <option value="right"<?PHP
156 if ($abook_take_location == 'right')
157 echo ' SELECTED';
158 ?>>Right aligned</option>
159 </select> on the Read screen<br>
160 <input type=checkbox name="abook_take_abook_take_hide"<?PHP
161 if ($abook_take_hide)
162 echo ' CHECKED';
163 ?>> Hide the box<br>
164 <input type=checkbox name="abook_take_abook_take_verify"<?PHP
165 if ($abook_take_verify)
166 echo ' CHECKED';
167 ?>> Try to verify addresses
168 </td></tr><?PHP
169 }
170
171
172 function abook_take_save()
173 {
174 global $username, $data_dir;
175 global $abook_take_abook_take_location;
176 global $abook_take_abook_take_hide;
177 global $abook_take_abook_take_verify;
178
179
180 if (isset($abook_take_abook_take_location))
181 {
182 setPref($data_dir, $username, 'abook_take_location', $abook_take_abook_take_location);
183 }
184 else
185 {
186 setPref($data_dir, $username, 'abook_take_location', 'center');
187 }
188
189 if (isset($abook_take_abook_take_hide))
190 {
191 setPref($data_dir, $username, 'abook_take_hide', '1');
192 }
193 else
194 {
195 setPref($data_dir, $username, 'abook_take_hide', '');
196 }
197
198 if (isset($abook_take_abook_take_verify))
199 {
200 setPref($data_dir, $username, 'abook_take_verify', '1');
201 }
202 else
203 {
204 setPref($data_dir, $username, 'abook_take_verify', '');
205 }
206 }
207
208 ?>