We're living in 2004 now... perl is your friend for these kinds of things :)
[squirrelmail.git] / plugins / abook_take / setup.php
1 <?php
2
3 /**
4 * setup.php
5 *
6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
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 * $Id$
14 * @package plugins
15 * @subpackage abook_take
16 */
17
18 /**
19 * If SM_PATH isn't defined, define it. Required to include files.
20 * @ignore
21 */
22 if (!defined('SM_PATH')) {
23 define('SM_PATH','../../');
24 }
25
26 /* SquirrelMail required files. */
27 require_once(SM_PATH . 'functions/url_parser.php');
28
29 /**
30 * Initialize the plugin
31 */
32 function squirrelmail_plugin_init_abook_take()
33 {
34 global $squirrelmail_plugin_hooks;
35
36 $squirrelmail_plugin_hooks['read_body_bottom']['abook_take'] = 'abook_take_read';
37 $squirrelmail_plugin_hooks['loading_prefs']['abook_take'] = 'abook_take_pref';
38 $squirrelmail_plugin_hooks['options_display_inside']['abook_take'] = 'abook_take_options';
39 $squirrelmail_plugin_hooks['options_display_save']['abook_take'] = 'abook_take_save';
40 }
41
42 function valid_email ($email, $verify)
43 {
44 global $Email_RegExp_Match;
45
46 if (! eregi('^' . $Email_RegExp_Match . '$', $email))
47 return false;
48
49 if (! $verify)
50 return true;
51
52 return checkdnsrr(substr(strstr($email, '@'), 1), 'ANY') ;
53 }
54
55 function abook_take_read_string($str)
56 {
57 global $abook_found_email, $Email_RegExp_Match;
58
59 while (eregi('(' . $Email_RegExp_Match . ')', $str, $hits))
60 {
61 $str = substr(strstr($str, $hits[0]), strlen($hits[0]));
62 if (! isset($abook_found_email[$hits[0]]))
63 {
64 echo '<input type="hidden" name="email[]" value="' .
65 htmlspecialchars($hits[0]) . "\" />\n";
66 $abook_found_email[$hits[0]] = 1;
67 }
68 }
69
70 return;
71 }
72
73 function abook_take_read_array($array)
74 {
75 foreach ($array as $item)
76 abook_take_read_string($item->getAddress());
77 }
78
79 function abook_take_read()
80 {
81 global $message;
82
83 echo '<br /><form action="../plugins/abook_take/take.php" method="post"><center>'."\n";
84
85 if (isset($message->rfc822_header->reply_to))
86 abook_take_read_array($message->rfc822_header->reply_to);
87 if (isset($message->rfc822_header->from))
88 abook_take_read_array($message->rfc822_header->from);
89 if (isset($message->rfc822_header->cc))
90 abook_take_read_array($message->rfc822_header->cc);
91 if (isset($message->rfc822_header->to))
92 abook_take_read_array($message->rfc822_header->to);
93
94 echo '<input type="submit" value="' . _("Take Address") . '" />' .
95 '</center></form>';
96 }
97
98 function abook_take_pref()
99 {
100 global $username, $data_dir, $abook_take_verify;
101
102 $abook_take_verify = getPref($data_dir, $username, 'abook_take_verify');
103 }
104
105 function abook_take_options()
106 {
107 global $abook_take_verify;
108
109 echo '<tr>' . html_tag('td',_("Address Book Take:"),'right','','nowrap') . "\n" .
110 '<td><input name="abook_take_abook_take_verify" type="checkbox"';
111 if (isset($abook_take_verify) && $abook_take_verify)
112 echo ' checked';
113 echo ' /> ' . _("Try to verify addresses") . "</td></tr>\n";
114 }
115
116
117 function abook_take_save()
118 {
119 global $username, $data_dir;
120
121 if (sqgetGlobalVar('abook_take_abook_take_verify', $abook_take_abook_take_verify, SQ_POST))
122 setPref($data_dir, $username, 'abook_take_verify', '1');
123 else
124 setPref($data_dir, $username, 'abook_take_verify', '');
125 }
126
127 ?>