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