a3eabb7ccfca6db0d1f7ca399d27576f2dd8971a
[squirrelmail.git] / plugins / abook_take / functions.php
1 <?php
2
3 /**
4 * functions.php
5 *
6 * Copyright (c) 1999-2005 The SquirrelMail Project Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
8 *
9 * Functions for the Address Take plugin
10 *
11 * $Id$
12 * @package plugins
13 * @subpackage abook_take
14 */
15
16 /** SquirrelMail required files. */
17 require_once(SM_PATH . 'functions/url_parser.php');
18 require_once(SM_PATH . 'functions/forms.php');
19
20 function valid_email ($email, $verify)
21 {
22 global $Email_RegExp_Match;
23
24 if (! eregi('^' . $Email_RegExp_Match . '$', $email))
25 return false;
26
27 if (! $verify)
28 return true;
29
30 return checkdnsrr(substr(strstr($email, '@'), 1), 'ANY') ;
31 }
32
33 function abook_take_read_string($str)
34 {
35 global $abook_found_email, $Email_RegExp_Match;
36
37 while (eregi('(' . $Email_RegExp_Match . ')', $str, $hits))
38 {
39 $str = substr(strstr($str, $hits[0]), strlen($hits[0]));
40 if (! isset($abook_found_email[$hits[0]]))
41 {
42 echo addHidden('email[]', $hits[0]);
43 $abook_found_email[$hits[0]] = 1;
44 }
45 }
46
47 return;
48 }
49
50 function abook_take_read_array($array)
51 {
52 foreach ($array as $item)
53 abook_take_read_string($item->getAddress());
54 }
55
56 function abook_take_read()
57 {
58 global $message;
59
60 echo '<br />' . addForm(SM_PATH . 'plugins/abook_take/take.php') .
61 '<center>' . "\n";
62
63 if (isset($message->rfc822_header->reply_to))
64 abook_take_read_array($message->rfc822_header->reply_to);
65 if (isset($message->rfc822_header->from))
66 abook_take_read_array($message->rfc822_header->from);
67 if (isset($message->rfc822_header->cc))
68 abook_take_read_array($message->rfc822_header->cc);
69 if (isset($message->rfc822_header->to))
70 abook_take_read_array($message->rfc822_header->to);
71
72 echo addSubmit(_("Take Address")) .
73 '</center></form>';
74 }
75
76 function abook_take_pref()
77 {
78 global $username, $data_dir, $abook_take_verify;
79
80 $abook_take_verify = getPref($data_dir, $username, 'abook_take_verify', false);
81 }
82
83 function abook_take_options()
84 {
85 global $abook_take_verify;
86
87 echo '<tr>' . html_tag('td',_("Address Book Take:"),'right','','style="white-space: nowrap;"') . "\n" . '<td>' .
88 addCheckbox('abook_take_abook_take_verify', $abook_take_verify) .
89 _("Try to verify addresses") . "</td></tr>\n";
90 }
91
92 function abook_take_save()
93 {
94 global $username, $data_dir;
95
96 if (sqgetGlobalVar('abook_take_abook_take_verify', $abook_take_abook_take_verify, SQ_POST))
97 setPref($data_dir, $username, 'abook_take_verify', '1');
98 else
99 setPref($data_dir, $username, 'abook_take_verify', '');
100 }
101
102 ?>