Source for file fetch.php
Documentation is available at fetch.php
* @copyright 1999-2020 The SquirrelMail Project Team
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
* @version $Id: fetch.php 14840 2020-01-07 07:42:38Z pdontthink $
require_once(SM_PATH .
'include/validate.php');
include_once(SM_PATH .
'functions/imap.php');
include_once(SM_PATH .
'plugins/mail_fetch/class.POP3.php');
include_once(SM_PATH .
'plugins/mail_fetch/functions.php' );
// don't load this page if this plugin is not enabled
if (!in_array('mail_fetch', $plugins)) exit;
global $imap_stream_options; // in case not defined in config
$mailfetch_server_number =
getPref($data_dir, $username, "mailfetch_server_number");
if (!isset
($mailfetch_server_number)) $mailfetch_server_number=
0;
$mailfetch_cypher =
getPref($data_dir, $username, "mailfetch_cypher");
if ($mailfetch_server_number<
1) $mailfetch_server_number=
0;
for ($i=
0;$i<
$mailfetch_server_number;$i++
) {
$mailfetch_server_[$i] =
getPref($data_dir, $username, "mailfetch_server_$i");
$mailfetch_port_[$i] =
getPref($data_dir, $username, "mailfetch_port_$i");
$mailfetch_alias_[$i] =
getPref($data_dir, $username, "mailfetch_alias_$i");
$mailfetch_user_[$i] =
getPref($data_dir, $username, "mailfetch_user_$i");
$mailfetch_pass_[$i] =
getPref($data_dir, $username, "mailfetch_pass_$i");
$mailfetch_lmos_[$i] =
getPref($data_dir, $username, "mailfetch_lmos_$i");
$mailfetch_login_[$i] =
getPref($data_dir, $username, "mailfetch_login_$i");
$mailfetch_uidl_[$i] =
getPref($data_dir, $username, "mailfetch_uidl_$i");
$mailfetch_subfolder_[$i] =
getPref($data_dir, $username, "mailfetch_subfolder_$i");
if( $mailfetch_cypher ==
'on' ) {
$mailfetch_pass_[$i] =
decrypt( $mailfetch_pass_[$i] );
html_tag( 'td', '<b>' .
_("Remote POP server Fetching Mail") .
'</b>', 'center', $color[0] )
'center', '', 'width="95%" cols="1"' );
// get $server_to_fetch from globals, if not set display a choice to the user
echo
'<font size=-5><br></font>' .
"<form action=\"$PHP_SELF\" method=\"post\" target=\"_self\">" .
html_tag( 'table', '', 'center', '', 'width="70%" cols="2"' ) .
html_tag( 'td', _("Select Server:") .
' ', 'right' ) .
'<select name="server_to_fetch" size="1">' .
'<option value="all" selected>..' .
_("All") .
"...\n";
for ($i=
0;$i<
$mailfetch_server_number;$i++
) {
echo
"<option value=\"$i\">" .
//if password not set, ask for it
for ($i=
0;$i<
$mailfetch_server_number;$i++
) {
if ($mailfetch_pass_[$i]==
'') {
html_tag( 'td', '<input type="password" name="pass_' .
$i .
'">', 'left' )
html_tag( 'td', '<input type=submit name=submit_mailfetch value="' .
_("Fetch Mail").
'">', 'left' )
if ( $server_to_fetch ==
'all' ) {
$i_stop =
$mailfetch_server_number;
$i_start =
$server_to_fetch;
for ($i_loop=
$i_start;$i_loop<
$i_stop;$i_loop++
) {
$mailfetch_server=
$mailfetch_server_[$i_loop];
$mailfetch_port=
$mailfetch_port_[$i_loop];
$mailfetch_user=
$mailfetch_user_[$i_loop];
if ($mailfetch_pass_[$i_loop] ==
'') {
$mailfetch_pass =
$mailfetch_pass_[$i_loop];
$mailfetch_lmos=
$mailfetch_lmos_[$i_loop];
$mailfetch_login=
$mailfetch_login_[$i_loop];
$mailfetch_uidl=
$mailfetch_uidl_[$i_loop];
$mailfetch_subfolder=
$mailfetch_subfolder_[$i_loop];
$pop3 =
new POP3($mailfetch_server, 60);
html_tag( 'td', '<b>' .
_("Fetching from ") .
if (!$pop3->connect($mailfetch_server,$mailfetch_port)) {
$imap_stream =
sqimap_login($username, $key, $imapServerAddress, $imapPort, 10, $imap_stream_options);
// check if destination folder is not set, is not subscribed and is not \noselect folder
if($mailfetch_subfolder ==
'' ||
$mailfetch_subfolder =
'INBOX';
$Count =
$pop3->login($mailfetch_user, $mailfetch_pass);
if (($Count ==
false ||
$Count == -
1) &&
$pop3->ERROR !=
'') {
// register_shutdown_function($pop3->quit());
$msglist =
$pop3->uidl();
for ($j =
1; $j <
sizeof($msglist); $j++
) {
if ($msglist["$j"] ==
$mailfetch_uidl) {
$newmsgcount =
$Count -
$i +
1;
// Faster to get them all at once
$mailfetch_uidl =
$pop3->uidl();
if (! is_array($mailfetch_uidl) &&
$mailfetch_lmos ==
'on')
if ($mailfetch_lmos ==
'on') {
for (; $i <=
$Count; $i++
) {
$MessArray =
$pop3->get($i);
while ( (!$MessArray) or (gettype($MessArray) !=
"array")) {
if (!$pop3->connect($mailfetch_server)) {
setPref($data_dir,$username,"mailfetch_uidl_$i_loop", $mailfetch_uidl[$i-
1]);
$Count =
$pop3->login($mailfetch_user, $mailfetch_pass);
if (($Count ==
false ||
$Count == -
1) &&
$pop3->ERROR !=
'') {
setPref($data_dir,$username,"mailfetch_uidl_$i_loop", $mailfetch_uidl[$i-
1]);
$MessArray =
$pop3->get($i);
while (list
($lineNum, $line) =
each ($MessArray)) {
fputs($imap_stream, "A3$i APPEND \"$mailfetch_subfolder\" {" .
strlen($Message) .
"}\r\n");
$Line =
fgets($imap_stream, 1024);
if (substr($Line, 0, 1) ==
'+') {
fputs($imap_stream, $Message);
fputs($imap_stream, "\r\n");
if ( $response <>
'OK' ) {
setPref($data_dir,$username,"mailfetch_uidl_$i_loop", $mailfetch_uidl[$i-
1]);
if ($mailfetch_lmos !=
'on') {
if( $pop3->delete($i) ) {
setPref($data_dir,$username,"mailfetch_uidl_$i_loop", $mailfetch_uidl[$i-
1]);
setPref($data_dir,$username,"mailfetch_uidl_$i_loop", array_pop($mailfetch_uidl));
Documentation generated on Mon, 13 Jan 2020 04:24:35 +0100 by phpDocumentor 1.4.3