squirrelmail-webmail  1.4.22
About: SquirrelMail is a standards-based webmail package with strong MIME support, address books, and folder manipulation (written in PHP4).
  Fossies Dox: squirrelmail-webmail-1.4.22.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

setup.php
Go to the documentation of this file.
1 <?php
2 
16 if (! defined('SM_PATH')) define('SM_PATH','../../');
17 
18 // FIXME: do we have to include them here.
19 require_once(SM_PATH . 'plugins/mail_fetch/functions.php' );
20 
23 
24  $squirrelmail_plugin_hooks['menuline']['mail_fetch'] = 'mail_fetch_link';
25  $squirrelmail_plugin_hooks['loading_prefs']['mail_fetch'] = 'mail_fetch_load_pref';
26  $squirrelmail_plugin_hooks['login_verified']['mail_fetch'] = 'mail_fetch_setnew';
27  $squirrelmail_plugin_hooks['left_main_before']['mail_fetch'] = 'mail_fetch_login';
28  $squirrelmail_plugin_hooks['optpage_register_block']['mail_fetch'] = 'mailfetch_optpage_register_block';
29  $squirrelmail_plugin_hooks['rename_or_delete_folder']['mail_fetch'] = 'mail_fetch_folderact';
30 }
31 
32 function mail_fetch_link() {
33  displayInternalLink('plugins/mail_fetch/fetch.php', _("Fetch"), '');
34  echo '&nbsp;&nbsp;';
35 }
36 
38  global $data_dir;
40  global $mailfetch_cypher, $mailfetch_port_;
41  global $mailfetch_server_,$mailfetch_alias_,$mailfetch_user_,$mailfetch_pass_;
42  global $mailfetch_lmos_, $mailfetch_uidl_, $mailfetch_login_, $mailfetch_fref_;
43  global $PHP_SELF;
44 
45  sqgetGlobalVar('username', $username, SQ_SESSION);
46 
47  if( stristr( $PHP_SELF, 'mail_fetch' ) ) {
48  $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number', 0);
49  $mailfetch_cypher = getPref($data_dir, $username, 'mailfetch_cypher', 'on' );
51  for ($i=0;$i<$mailfetch_server_number;$i++) {
52  $mailfetch_server_[$i] = getPref($data_dir, $username, "mailfetch_server_$i");
53  $mailfetch_port_[$i] = getPref($data_dir, $username, "mailfetch_port_$i");
54  $mailfetch_alias_[$i] = getPref($data_dir, $username, "mailfetch_alias_$i");
55  $mailfetch_user_[$i] = getPref($data_dir, $username, "mailfetch_user_$i");
56  $mailfetch_pass_[$i] = getPref($data_dir, $username, "mailfetch_pass_$i");
57  $mailfetch_lmos_[$i] = getPref($data_dir, $username, "mailfetch_lmos_$i");
58  $mailfetch_login_[$i] = getPref($data_dir, $username, "mailfetch_login_$i");
59  $mailfetch_fref_[$i] = getPref($data_dir, $username, "mailfetch_fref_$i");
60  $mailfetch_uidl_[$i] = getPref($data_dir, $username, "mailfetch_uidl_$i");
61  if( $mailfetch_cypher == 'on' ) $mailfetch_pass_[$i] = decrypt( $mailfetch_pass_[$i] );
62  }
63  }
64 }
65 
66 function mail_fetch_login() {
67  require_once (SM_PATH . 'include/validate.php');
68  include_once (SM_PATH . 'functions/imap.php');
69  require_once (SM_PATH . 'plugins/mail_fetch/class.POP3.php');
70  require_once (SM_PATH . 'plugins/mail_fetch/functions.php');
71 
73 
74  sqgetGlobalVar('username', $username, SQ_SESSION);
75  sqgetGlobalVar('key', $key, SQ_COOKIE);
76 
77  $mailfetch_newlog = getPref($data_dir, $username, 'mailfetch_newlog');
78 
79  $outMsg = '';
80 
81  $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number');
83  $mailfetch_cypher = getPref($data_dir, $username, 'mailfetch_cypher');
85 
86  for ($i_loop=0;$i_loop<$mailfetch_server_number;$i_loop++) {
87 
88  $mailfetch_login_[$i_loop] = getPref($data_dir, $username, "mailfetch_login_$i_loop");
89  $mailfetch_fref_[$i_loop] = getPref($data_dir, $username, "mailfetch_fref_$i_loop");
90  $mailfetch_pass_[$i_loop] = getPref($data_dir, $username, "mailfetch_pass_$i_loop");
91  if( $mailfetch_cypher == 'on' )
92  $mailfetch_pass_[$i_loop] = decrypt( $mailfetch_pass_[$i_loop] );
93 
94  if( $mailfetch_pass_[$i_loop] <> '' && // Empty passwords no allowed
95  ( ( $mailfetch_login_[$i_loop] == 'on' && $mailfetch_newlog == 'on' ) || $mailfetch_fref_[$i_loop] == 'on' ) ) {
96 
97  $mailfetch_server_[$i_loop] = getPref($data_dir, $username, "mailfetch_server_$i_loop");
98  $mailfetch_port_[$i_loop] = getPref($data_dir, $username , "mailfetch_port_$i_loop");
99  $mailfetch_alias_[$i_loop] = getPref($data_dir, $username, "mailfetch_alias_$i_loop");
100  $mailfetch_user_[$i_loop] = getPref($data_dir, $username, "mailfetch_user_$i_loop");
101  $mailfetch_lmos_[$i_loop] = getPref($data_dir, $username, "mailfetch_lmos_$i_loop");
102  $mailfetch_uidl_[$i_loop] = getPref($data_dir, $username, "mailfetch_uidl_$i_loop");
103  $mailfetch_subfolder_[$i_loop] = getPref($data_dir, $username, "mailfetch_subfolder_$i_loop");
104 
105  $mailfetch_server=$mailfetch_server_[$i_loop];
106  $mailfetch_port=$mailfetch_port_[$i_loop];
107  $mailfetch_user=$mailfetch_user_[$i_loop];
108  $mailfetch_alias=$mailfetch_alias_[$i_loop];
109  $mailfetch_pass=$mailfetch_pass_[$i_loop];
110  $mailfetch_lmos=$mailfetch_lmos_[$i_loop];
111  $mailfetch_login=$mailfetch_login_[$i_loop];
112  $mailfetch_uidl=$mailfetch_uidl_[$i_loop];
113  $mailfetch_subfolder=$mailfetch_subfolder_[$i_loop];
114 
115  // $outMsg .= "$mailfetch_alias checked<br>";
116 
117  // $outMsg .= "$mailfetch_alias_[$i_loop]<br>";
118 
119  $pop3 = new POP3($mailfetch_server, 60);
120 
121  if (!$pop3->connect($mailfetch_server,$mailfetch_port)) {
122  $outMsg .= _("Warning, ") . $pop3->ERROR;
123  continue;
124  }
125 
127 
128  $Count = $pop3->login($mailfetch_user, $mailfetch_pass);
129  if (($Count == false || $Count == -1) && $pop3->ERROR != '') {
130  $outMsg .= _("Login Failed:") . $pop3->ERROR;
131  continue;
132  }
133 
134  // register_shutdown_function($pop3->quit());
135 
136  $msglist = $pop3->uidl();
137 
138  $i = 1;
139  for ($j = 1; $j < sizeof($msglist); $j++) {
140  if ($msglist["$j"] == $mailfetch_uidl) {
141  $i = $j+1;
142  break;
143  }
144  }
145 
146  if ($Count < $i) {
147  $pop3->quit();
148  continue;
149  }
150  if ($Count == 0) {
151  $pop3->quit();
152  continue;
153  } else {
154  $newmsgcount = $Count - $i + 1;
155  }
156 
157  // Faster to get them all at once
158  $mailfetch_uidl = $pop3->uidl();
159 
160  if (! is_array($mailfetch_uidl) && $mailfetch_lmos == 'on')
161  $outMsg .= _("Server does not support UIDL.");
162 
163  for (; $i <= $Count; $i++) {
164  if (!ini_get('safe_mode'))
165  set_time_limit(20); // 20 seconds per message max
166  $Message = "";
167  $MessArray = $pop3->get($i);
168 
169  if ( (!$MessArray) or (gettype($MessArray) != "array")) {
170  $outMsg .= _("Warning, ") . $pop3->ERROR;
171  continue 2;
172  }
173 
174  while (list($lineNum, $line) = each ($MessArray)) {
175  $Message .= $line;
176  }
177 
183  if ($mailfetch_subfolder=='' ||
184  ! mail_fetch_check_folder($imap_stream,$mailfetch_subfolder)) {
185  fputs($imap_stream, "A3$i APPEND INBOX {" . strlen($Message) . "}\r\n");
186  } else {
187  fputs($imap_stream, "A3$i APPEND $mailfetch_subfolder {" . strlen($Message) . "}\r\n");
188  }
189  $Line = fgets($imap_stream, 1024);
190  if (substr($Line, 0, 1) == '+') {
191  fputs($imap_stream, $Message);
192  fputs($imap_stream, "\r\n");
193  sqimap_read_data($imap_stream, "A3$i", false, $response, $message);
194 
195  if ($mailfetch_lmos != 'on') {
196  $pop3->delete($i);
197  }
198  } else {
199  echo "$Line";
200  $outMsg .= _("Error Appending Message!");
201  }
202  }
203 
204  $pop3->quit();
206  if (is_array($mailfetch_uidl)) {
207  setPref($data_dir,$username,"mailfetch_uidl_$i_loop", array_pop($mailfetch_uidl));
208  }
209  }
210  }
211 
212  if( trim( $outMsg ) <> '' ) {
213  echo '<br><font size="1">' . _("Mail Fetch Result:") . "<br>$outMsg</font>";
214  }
215  if( $mailfetch_newlog == 'on' ) {
216  setPref($data_dir, $username, 'mailfetch_newlog', 'off');
217  }
218 }
219 
220 function mail_fetch_setnew() {
221 
222  global $data_dir;
223  require_once(SM_PATH . 'functions/prefs.php');
224 
225  sqgetGlobalVar('username', $username, SQ_SESSION);
226 
227  setPref( $data_dir, $username, 'mailfetch_newlog', 'on' );
228 }
229 
231  global $optpage_blocks;
232 
233  $optpage_blocks[] = array(
234  'name' => _("POP3 Fetch Mail"),
235  'url' => '../plugins/mail_fetch/options.php',
236  'desc' => _("This configures settings for downloading email from a POP3 mailbox to your account on this server."),
237  'js' => false
238  );
239 }
240 
241 function mail_fetch_folderact($args) {
242  global $username, $data_dir;
243 
244  if (empty($args) || !is_array($args)) {
245  return;
246  }
247 
248  /* Should be 3 ars, 1: old folder, 2: action, 3: new folder */
249  if (count($args) != 3) {
250  return;
251  }
252 
253  list($old_folder, $action, $new_folder) = $args;
254 
255  $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number');
256 
257  for ($i = 0; $i < $mailfetch_server_number; $i++) {
258  $mailfetch_subfolder = getPref($data_dir, $username, 'mailfetch_subfolder_' . $i);
259 
260  if ($mailfetch_subfolder != $old_folder) {
261  continue;
262  }
263 
264  if ($action == 'delete') {
265  setPref($data_dir, $username, 'mailfetch_subfolder_' . $i, 'INBOX');
266  } elseif ($action == 'rename') {
267  setPref($data_dir, $username, 'mailfetch_subfolder_' . $i, $new_folder);
268  }
269  }
270 }
elseif
if(! sqgetGlobalVar('sound', $sound, SQ_GET)) elseif($sound=='(none)')
Definition: testsound.php:25
sqgetGlobalVar
sqgetGlobalVar($name, &$value, $search=SQ_INORDER)
Definition: global.php:344
getPref
getPref($data_dir, $username, $string, $default='')
Definition: db_prefs.php:316
$mailfetch_server_number
$mailfetch_server_number
Definition: fetch.php:45
$imapServerAddress
$imapServerAddress
Definition: config_default.php:202
sqimap_login
sqimap_login($username, $password, $imap_server_address, $imap_port, $hide)
Definition: imap_general.php:481
mail_fetch_folderact
mail_fetch_folderact($args)
Definition: setup.php:241
$data_dir
$data_dir
Definition: config_default.php:499
SQ_SESSION
const SQ_SESSION
Definition: global.php:18
$imap_stream
$imap_stream
Definition: bug_report.php:119
mail_fetch_setnew
mail_fetch_setnew()
Definition: setup.php:220
setPref
setPref($data_dir, $username, $string, $set_to)
Definition: db_prefs.php:352
mailfetch_optpage_register_block
mailfetch_optpage_register_block()
Definition: setup.php:230
$username
global $username
Definition: validate.php:55
POP3
Definition: class.POP3.php:21
$message
$message
Definition: download.php:54
mail_fetch_login
mail_fetch_login()
Definition: setup.php:66
squirrelmail_plugin_init_mail_fetch
squirrelmail_plugin_init_mail_fetch()
Definition: setup.php:21
$PHP_SELF
$PHP_SELF
Definition: strings.php:1458
$squirrelmail_plugin_hooks
global $squirrelmail_plugin_hooks
Definition: plugin.php:17
$mailfetch_cypher
$mailfetch_cypher
Definition: fetch.php:47
sqimap_logout
sqimap_logout($imap_stream)
Definition: imap_general.php:639
mail_fetch_check_folder
mail_fetch_check_folder($imap_stream, $imap_folder)
Definition: functions.php:156
mail_fetch_link
mail_fetch_link()
Definition: setup.php:32
$j
for($i=0; $i< $numboxes; $i++) $j
Definition: empty_trash.php:72
decrypt
decrypt( $txt)
Definition: functions.php:138
sqimap_read_data
sqimap_read_data($imap_stream, $tag_uid, $handle_errors, &$response, &$message, $query='', $filter=false, $outputstream=false, $no_return=false)
Definition: imap_general.php:454
SM_PATH
const SM_PATH
Definition: decrypt_headers.php:16
$action
$action
Definition: options.php:34
_
_($str)
Definition: gettext.php:160
$imapPort
$imapPort
Definition: config_default.php:210
SQ_COOKIE
const SQ_COOKIE
Definition: global.php:19
mail_fetch_load_pref
mail_fetch_load_pref()
Definition: setup.php:37
displayInternalLink
displayInternalLink($path, $text, $target='')
Definition: page_header.php:101