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