We're living in 2004 now... perl is your friend for these kinds of things :)
[squirrelmail.git] / plugins / abook_take / setup.php
CommitLineData
e8b140ab 1<?php
2
b755a6b1 3/**
4 * setup.php
5 *
82d304a0 6 * Copyright (c) 1999-2004 The SquirrelMail Project Team
b755a6b1 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$
ea5f4b8e 14 * @package plugins
15 * @subpackage abook_take
b755a6b1 16 */
17
ea5f4b8e 18/**
19 * If SM_PATH isn't defined, define it. Required to include files.
20 * @ignore
21 */
c3c84392 22if (!defined('SM_PATH')) {
b755a6b1 23 define('SM_PATH','../../');
c3c84392 24}
d55c0f66 25
08185f2a 26/* SquirrelMail required files. */
27require_once(SM_PATH . 'functions/url_parser.php');
e8b140ab 28
ea5f4b8e 29/**
30 * Initialize the plugin
31 */
e8b140ab 32function squirrelmail_plugin_init_abook_take()
33{
b755a6b1 34 global $squirrelmail_plugin_hooks;
e8b140ab 35
b755a6b1 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';
e8b140ab 40}
41
e8b140ab 42function valid_email ($email, $verify)
43{
b755a6b1 44 global $Email_RegExp_Match;
e8b140ab 45
b755a6b1 46 if (! eregi('^' . $Email_RegExp_Match . '$', $email))
47 return false;
e8b140ab 48
b755a6b1 49 if (! $verify)
50 return true;
d55c0f66 51
b755a6b1 52 return checkdnsrr(substr(strstr($email, '@'), 1), 'ANY') ;
e8b140ab 53}
54
e8b140ab 55function abook_take_read_string($str)
56{
b755a6b1 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 }
d55c0f66 69
b755a6b1 70 return;
e8b140ab 71}
72
e8b140ab 73function abook_take_read_array($array)
74{
b755a6b1 75 foreach ($array as $item)
76 abook_take_read_string($item->getAddress());
e8b140ab 77}
78
e8b140ab 79function abook_take_read()
80{
b755a6b1 81 global $message;
e8b140ab 82
b755a6b1 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>';
e8b140ab 96}
97
98function abook_take_pref()
99{
b755a6b1 100 global $username, $data_dir, $abook_take_verify;
e8b140ab 101
b755a6b1 102 $abook_take_verify = getPref($data_dir, $username, 'abook_take_verify');
e8b140ab 103}
104
e8b140ab 105function abook_take_options()
106{
b755a6b1 107 global $abook_take_verify;
108
a75e70b1 109 echo '<tr>' . html_tag('td',_("Address Book Take:"),'right','','nowrap') . "\n" .
b755a6b1 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";
e8b140ab 114}
115
116
117function abook_take_save()
118{
b755a6b1 119 global $username, $data_dir;
e8b140ab 120
b755a6b1 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', '');
e8b140ab 125}
126
127?>