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 14845 2020-01-07 08:09:34Z pdontthink $
* Include the SquirrelMail initialization file.
require
('../../include/init.php');
include_once(SM_PATH .
'functions/imap_general.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
* @param string $msg message
global $data_dir, $username;
$mailfetch['server_number'] =
getPref($data_dir, $username, "mailfetch_server_number");
if (!isset
($mailfetch['server_number']) ||
($mailfetch['server_number'] <
1)) {
$mailfetch['server_number'] =
0;
$mailfetch['cypher'] =
getPref($data_dir, $username, "mailfetch_cypher");
for ($i =
0; $i <
$mailfetch['server_number']; $i++
) {
$mailfetch[$i]['server'] =
getPref($data_dir, $username, "mailfetch_server_$i");
$mailfetch[$i]['port'] =
getPref($data_dir, $username, "mailfetch_port_$i");
$mailfetch[$i]['alias'] =
getPref($data_dir, $username, "mailfetch_alias_$i");
$mailfetch[$i]['user'] =
getPref($data_dir, $username, "mailfetch_user_$i");
$mailfetch[$i]['pass'] =
getPref($data_dir, $username, "mailfetch_pass_$i");
if($mailfetch['cypher'] ==
'on') {
$mailfetch[$i]['pass'] =
decrypt($mailfetch[$i]['pass']);
if ($mailfetch[$i]['pass'] ==
'') {
$mailfetch[$i]['lmos'] =
getPref($data_dir, $username, "mailfetch_lmos_$i");
$mailfetch[$i]['login'] =
getPref($data_dir, $username, "mailfetch_login_$i");
$mailfetch[$i]['uidl'] =
getPref($data_dir, $username, "mailfetch_uidl_$i");
$mailfetch[$i]['subfolder'] =
getPref($data_dir, $username, "mailfetch_subfolder_$i");
if($mailfetch[$i]['alias'] ==
'') {
$mailfetch[$i]['alias'] ==
$mailfetch[$i]['server'];
// Authentication type (added in 1.5.2)
// Connection type (added in 1.5.2)
* @param array $mailfetch
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="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[$i]['pass'] ==
'') {
html_tag( 'td', '<input type="password" name="pass_' .
$i .
'" />', 'left' )
html_tag( 'td', '<input type="submit" name="submit_mailfetch" value="' .
_("Fetch Mail").
'" />', 'left' )
html_tag( 'td', '<b>' .
_("Remote POP server Fetching Mail") .
'</b>', 'center', $color[0] )
'center', '', 'width="95%" cols="1"' );
/* there are no servers defined yet... */
if($mailfetch['server_number'] ==
0) {
//FIXME: do not echo directly to browser -- use templates only
echo
'<p>' .
_("No POP3 servers configured yet.") .
'</p>';
_("Click here to go to the options page.") );
$oTemplate->display('footer.tpl');
// get $server_to_fetch from globals, if not set display a choice to the user
$oTemplate->display('footer.tpl');
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[$i_loop]['server'];
$mailfetch_port =
$mailfetch[$i_loop]['port'];
$mailfetch_user =
$mailfetch[$i_loop]['user'];
$mailfetch_pass =
$mailfetch[$i_loop]['pass'];
$mailfetch_lmos =
$mailfetch[$i_loop]['lmos'];
$mailfetch_login =
$mailfetch[$i_loop]['login'];
$mailfetch_uidl =
$mailfetch[$i_loop]['uidl'];
$mailfetch_subfolder =
$mailfetch[$i_loop]['subfolder'];
$mailfetch_auth =
$mailfetch[$i_loop]['auth'];
$mailfetch_type =
$mailfetch[$i_loop]['type'];
$pop3 =
new mail_fetch(array('host' =>
$mailfetch_server,
'port' =>
$mailfetch_port,
'auth' =>
$mailfetch_auth,
'tls' =>
$mailfetch_type,
if (!empty($pop3->error)) {
$imap_stream =
sqimap_login($username, false, $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';
if (! $pop3->login($mailfetch_user, $mailfetch_pass)) {
$aMsgStat =
$pop3->command_stat();
$Count =
$aMsgStat['count'];
// If we leave messages on server, try using UIDL
if ($mailfetch_lmos ==
'on') {
$msglist =
$pop3->command_uidl();
// User asked to leave messages on server, but we can't do that.
// $mailfetch_lmos = 'off';
// calculate number of new messages
for ($j =
1; $j <=
sizeof($msglist); $j++
) {
// do strict comparison ('1111.10' should not be equal to '1111.100')
if ($msglist[$j] ===
$mailfetch_uidl) {
// fetch list of messages with LIST
// we can use else control, but we can also set $mailfetch_lmos
// to off if server does not support UIDL.
if ($mailfetch_lmos !=
'on') {
$msglist =
$pop3->command_list();
$newmsgcount =
$Count -
$i +
1;
"Login OK: Inbox contains %s messages",$newmsgcount), $newmsgcount));
if ($mailfetch_lmos ==
'on') {
for (; $i <=
$Count; $i++
) {
$Message =
$pop3->command_retr($i);
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 ($mailfetch_lmos ==
'on') {
setPref($data_dir,$username,"mailfetch_uidl_$i_loop", $msglist[$i-
1]);
if ($mailfetch_lmos !=
'on') {
if( $pop3->command_dele($i) ) {
if ($mailfetch_lmos ==
'on') {
setPref($data_dir,$username,"mailfetch_uidl_$i_loop", $msglist[$i-
1]);
if ($mailfetch_lmos ==
'on' &&
is_array($msglist)) {
$oTemplate->display('footer.tpl');
Documentation generated on Mon, 13 Jan 2020 04:22:27 +0100 by phpDocumentor 1.4.3