Time to stop coding for tonight. Making this kind of terrible bugs is bad.
[squirrelmail.git] / plugins / abook_take / setup.php
CommitLineData
e8b140ab 1<?php
2
08185f2a 3/* Path for SquirrelMail required files. */
4define('SM_PATH','../../');
d55c0f66 5
08185f2a 6/* SquirrelMail required files. */
7require_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
13function 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
24function 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
41function 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
59function abook_take_read_array($array)
60{
61 $i = 0;
62 while ($i < count($array))
63 {
64 abook_take_read_string($array[$i]);
65 $i ++;
66 }
67}
68
69
70function 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
e8b140ab 86 abook_take_read_string($message->header->from);
87 abook_take_read_array($message->header->cc);
88 abook_take_read_array($message->header->reply_to);
89 abook_take_read_array($message->header->to);
90
91
92 $new_body = $body;
93 $pos = strpos($new_body,
4cf43843 94 '">' . _("Download this as a file") . '</a></center><br></small>');
e8b140ab 95 if (is_int($pos))
96 {
97 $new_body = substr($new_body, 0, $pos);
98 }
99
100 $trans = get_html_translation_table(HTML_ENTITIES);
101 $trans[' '] = '&nbsp;';
102 $trans = array_flip($trans);
103 $new_body = strtr($new_body, $trans);
104
105 $new_body = urldecode($new_body);
106 $new_body = strip_tags($new_body);
107
108 $new_body = strtr($new_body, "\n", ' ');
109
110 abook_take_read_string($body);
4cf43843 111
112 echo '<input type="submit" value="' . _("Take Address") . '">';
e8b140ab 113 ?>
e8b140ab 114 </td>
115 </tr>
116 </table>
117 </td>
118 </tr>
119 </table>
120 </form>
121 <?PHP
122}
123
124function abook_take_pref()
125{
126 global $username, $data_dir;
127 global $abook_take_hide, $abook_take_location, $abook_take_verify;
128
129 $abook_take_location = getPref($data_dir, $username, 'abook_take_location');
130 if ($abook_take_location == '')
131 $abook_take_location = 'center';
132
133 $abook_take_hide = getPref($data_dir, $username, 'abook_take_hide');
134 $abook_take_verify = getPref($data_dir, $username, 'abook_take_verify');
135}
136
137
138function abook_take_options()
139{
140 global $abook_take_location, $abook_take_hide, $abook_take_verify;
141
4cf43843 142 echo html_tag( 'tr' ) .
143 html_tag( 'td', _("Address Book Take") . ':', 'right', '', 'nowrap valign="top"' ) .
144 html_tag( 'td', '', 'left' ) .
145 '<select name="abook_take_abook_take_location">' .
146 '<option value="left"';
147 if ($abook_take_location == 'left')
148 echo ' selected';
149 echo '>' . _("Left aligned") . '</option>' .
150 '<option value="center"';
151 if ($abook_take_location == 'center')
152 echo ' selected';
153 echo '>' . _("Centered") . '</option>' .
154 '<option value="right"';
155 if ($abook_take_location == 'right')
156 echo ' selected';
157 echo '>' . _("Right aligned") . '</option>' .
158 '</select> ' . _("on the Read screen") .'<br>' .
159 '<input type="checkbox" name="abook_take_abook_take_hide"';
160 if ($abook_take_hide)
161 echo ' checked';
2798d757 162 echo '>&nbsp;' . _("Hide the box") . '<br>' .
4cf43843 163 '<input type=checkbox name="abook_take_abook_take_verify"';
164 if ($abook_take_verify)
165 echo ' checked';
2798d757 166 echo '>&nbsp;' . _("Try to verify addresses") . '</td></tr>';
e8b140ab 167}
168
169
170function abook_take_save()
171{
172 global $username, $data_dir;
173 global $abook_take_abook_take_location;
174 global $abook_take_abook_take_hide;
175 global $abook_take_abook_take_verify;
176
177
178 if (isset($abook_take_abook_take_location))
179 {
180 setPref($data_dir, $username, 'abook_take_location', $abook_take_abook_take_location);
181 }
182 else
183 {
184 setPref($data_dir, $username, 'abook_take_location', 'center');
185 }
186
187 if (isset($abook_take_abook_take_hide))
188 {
189 setPref($data_dir, $username, 'abook_take_hide', '1');
190 }
191 else
192 {
193 setPref($data_dir, $username, 'abook_take_hide', '');
194 }
195
196 if (isset($abook_take_abook_take_verify))
197 {
198 setPref($data_dir, $username, 'abook_take_verify', '1');
199 }
200 else
201 {
202 setPref($data_dir, $username, 'abook_take_verify', '');
203 }
204}
205
206?>