adding msg classes. Still need additional cleanup work on the _sock classes, but they are good enough to toss in here for now

This commit is contained in:
seek3r 2002-05-06 09:05:44 +00:00
parent 0ce7166f26
commit d23d4b1235
10 changed files with 5842 additions and 1 deletions

View File

@ -0,0 +1,81 @@
<?php
/**************************************************************************\
* phpGroupWare API - php IMAP SO access object constructor *
* This file written by Mark Peters <skeeter@phpgroupware.org> *
* and Angelo Tony Puglisi (Angles) <angles@phpgroupware.org> *
* Handles initializing the appropriate class dcom object *
* Copyright (C) 2001 Mark Peters *
* ------------------------------------------------------------------------- *
* This library is part of the phpGroupWare API *
* http://www.phpgroupware.org/api *
* ------------------------------------------------------------------------ *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, *
* or any later version. *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/
if (isset($p1) && ($p1) && ( (stristr($p1, 'imap') || stristr($p1, 'pop') || stristr($p1, 'nntp'))))
{
$msg_server_type = $p1;
}
else
{
$msg_server_type = $GLOBALS['phpgw_info']['user']['preferences']['email']['msg_server_type'];
}
print_debug('msg class constructor, param $p1', $p1);
print_debug('msg class constructor, $msg_server_type', $msg_server_type);
if (extension_loaded('imap') || function_exists('imap_open'))
{
$imap_builtin = True;
$sock_fname = '';
print_debug('imap builtin extension is available');
}
else
{
$imap_builtin = False;
$sock_fname = '_sock';
print_debug('imap builtin extension NOT available, using socket class');
}
// ----- include SOCKET or PHP-BUILTIN classes as necessary
if ($imap_builtin == False)
{
CreateObject('phpgwapi.network');
print_debug('created phpgwapi network class used with sockets');
}
//CreateObject('phpgwapi.msg_base'.$sock_fname);
include(PHPGW_INCLUDE_ROOT.'/phpgwapi/inc/class.msg_base'.$sock_fname.'.inc.php');
if (($msg_server_type == 'imap') || ($msg_server_type == 'imaps'))
{
include(PHPGW_INCLUDE_ROOT.'/phpgwapi/inc/class.msg_imap'.$sock_fname.'.inc.php');
}
elseif (($msg_server_type == 'pop3') || ($msg_server_type == 'pop3s'))
{
include(PHPGW_INCLUDE_ROOT.'/phpgwapi/inc/class.msg_pop3'.$sock_fname.'.inc.php');
}
elseif ($msg_server_type == 'nntp')
{
include(PHPGW_INCLUDE_ROOT.'/phpgwapi/inc/class.msg_nntp'.$sock_fname.'.inc.php');
}
elseif ((isset($msg_server_type)) && ($msg_server_type != ''))
{
// educated guess based on info being available:
include(PHPGW_INCLUDE_ROOT.'/phpgwapi/inc/class.msg_'.$GLOBALS['phpgw_info']['user']['preferences']['email']['msg_server_type'].$sock_fname.'.inc.php');
}
else
{
// DEFAULT FALL BACK:
include(PHPGW_INCLUDE_ROOT.'/phpgwapi/inc/class.msg_imap.inc.php');
}
?>

View File

@ -0,0 +1,177 @@
<?php
/**************************************************************************\
* phpGroupWare - E-Mail *
* http://www.phpgroupware.org *
* Based on Aeromail by Mark Cushman <mark@cushman.net> *
* http://the.cushman.net/ *
* -------------------------------------------- *
* This program is free software; you can redistribute it and/or modify it *
* under the terms of the GNU General Public License as published by the *
* Free Software Foundation; either version 2 of the License, or (at your *
* option) any later version. *
\**************************************************************************/
/* $Id$ */
class msg_base
{
var $msg_struct;
var $err = array("code","msg","desc");
var $msg_info = Array(Array());
var $tempfile;
var $folder_list_changed = False;
var $enable_utf7 = False;
var $imap_builtin = True;
var $force_msg_uids = False;
//var $att_files_dir;
var $force_check;
var $boundary,
$got_structure;
function msg_base()
{
$this->err["code"] = " ";
$this->err["msg"] = " ";
$this->err["desc"] = " ";
$this->tempfile = $GLOBALS['phpgw_info']['server']['temp_dir'].SEP.$GLOBALS['phpgw_info']['user']['sessionid'].'.mhd';
$this->force_check = false;
$this->got_structure = false;
}
function utf7_encode($data)
{
// handle utf7 encoding of folder names, if necessary
if (($this->enable_utf7 == False)
|| (function_exists('imap_utf7_encode') == False)
|| (!isset($data)))
{
return $data;
}
// data to and from the server can be either array or string
if (gettype($data) == 'array')
{
// array data
$return_array = Array();
for ($i=0; $i<count($data);$i++)
{
$return_array[$i] = $this->utf7_encode_string($data[$i]);
}
return $return_array;
}
elseif (gettype($data) == 'string')
{
// string data
return $this->utf7_encode_string($data);
}
else
{
// ERROR
return $data;
}
}
function utf7_encode_string($data_str)
{
$name = Array();
$name['folder_before'] = '';
$name['folder_after'] = '';
$name['translated'] = '';
// folder name at this stage is {SERVER_NAME:PORT}FOLDERNAME
// get everything to the right of the bracket "}", INCLUDES the bracket itself
$name['folder_before'] = strstr($data_str,'}');
// get rid of that 'needle' "}"
$name['folder_before'] = substr($name['folder_before'], 1);
// translate
$name['folder_after'] = imap_utf7_encode($name['folder_before']);
// replace old folder name with new folder name
$name['translated'] = str_replace($name['folder_before'], $name['folder_after'], $data_str);
return $name['translated'];
}
function utf7_decode($data)
{
// handle utf7 decoding of folder names, if necessary
if (($this->enable_utf7 == False)
|| (function_exists('imap_utf7_decode') == False)
|| (!isset($data)))
{
return $data;
}
// data to and from the server can be either array or string
if (gettype($data) == 'array')
{
// array data
$return_array = Array();
for ($i=0; $i<count($data);$i++)
{
$return_array[$i] = $this->utf7_decode_string($data[$i]);
}
return $return_array;
}
elseif (gettype($data) == 'string')
{
// string data
return $this->utf7_decode_string($data);
}
else
{
// ERROR
return $data;
}
}
function utf7_decode_string($data_str)
{
$name = Array();
$name['folder_before'] = '';
$name['folder_after'] = '';
$name['translated'] = '';
// folder name at this stage is {SERVER_NAME:PORT}FOLDERNAME
// get everything to the right of the bracket "}", INCLUDES the bracket itself
$name['folder_before'] = strstr($data_str,'}');
// get rid of that 'needle' "}"
$name['folder_before'] = substr($name['folder_before'], 1);
// translate
$name['folder_after'] = imap_utf7_decode($name['folder_before']);
// "imap_utf7_decode" returns False if no translation occured
if ($name['folder_after'] == False)
{
// no translation occured
return $data_str;
}
else
{
// replace old folder name with new folder name
$name['translated'] = str_replace($name['folder_before'], $name['folder_after'], $data_str);
return $name['translated'];
}
}
function get_flag($stream,$msg_num,$flag)
{
$header = $this->fetchheader($stream,$msg_num);
$flag = strtolower($flag);
for ($i=0;$i<count($header);$i++)
{
$pos = strpos($header[$i],":");
if (is_int($pos) && $pos)
{
$keyword = trim(substr($header[$i],0,$pos));
$content = trim(substr($header[$i],$pos+1));
if (strtolower($keyword) == $flag)
{
return $content;
}
}
}
return false;
}
} // end of class mail
?>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,366 @@
<?php
/**************************************************************************\
* phpGroupWare Email - IMAP abstraction *
* http://www.phpgroupware.org/api *
* This file written by Itzchak Rehberg <izzy@phpgroupware.org> *
* and Joseph Engo <jengo@phpgroupware.org> *
* Mail function abstraction for IMAP servers *
* Copyright (C) 2000, 2001 Itzchak Rehberg *
* ------------------------------------------------------------------------- *
* This library is part of phpGroupWare (http://www.phpgroupware.org) *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, *
* or any later version. *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/
/* $Id$ */
class msg extends msg_base
{
function append($stream, $folder, $message, $flags=0)
{
$folder = $this->utf7_encode($folder);
return imap_append($stream, $folder, $message, $flags);
}
function base64($text)
{
return imap_base64($text);
}
function close($stream,$flags='')
{
return imap_close($stream,$flags);
}
function createmailbox($stream,$mailbox)
{
$mailbox = $this->utf7_encode($mailbox);
$this->folder_list_changed = True;
return imap_createmailbox($stream,$mailbox);
}
function deletemailbox($stream,$mailbox)
{
$this->folder_list_changed = True;
$mailbox = $this->utf7_encode($mailbox);
return imap_deletemailbox($stream,$mailbox);
}
function renamemailbox($stream,$mailbox_old,$mailbox_new)
{
$this->folder_list_changed = True;
$mailbox_old = $this->utf7_encode($mailbox_old);
$mailbox_new = $this->utf7_encode($mailbox_new);
return imap_renamemailbox($stream,$mailbox_old,$mailbox_new);
}
function delete($stream,$msg_num,$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & FT_UID)) )
{
$flags |= FT_UID;
}
return imap_delete($stream,$msg_num,$flags);
}
function expunge($stream)
{
return imap_expunge($stream);
}
function fetchbody($stream,$msgnr,$partnr,$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & FT_UID)) )
{
$flags |= FT_UID;
}
return imap_fetchbody($stream,$msgnr,$partnr,$flags);
}
function header($stream,$msg_nr,$fromlength='',$tolength='',$defaulthost='')
{
// do we need to temporarily switch to regular msg num sequence for this function?
if ($this->force_msg_uids == True)
{
// this function can nothandle UIDs, switch to sequence number
$new_msg_nr = imap_msgno($stream,$msg_nr);
if ($new_msg_nr)
{
$msg_nr = $new_msg_nr;
}
}
return imap_header($stream,$msg_nr,$fromlength,$tolength,$defaulthost);
}
function headers($stream)
{
return imap_headers($stream);
}
function fetch_raw_mail($stream,$msg_num,$flags=0)
{
$flags |= FT_PREFETCHTEXT;
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & FT_UID)) )
{
$flags |= FT_UID;
}
return imap_fetchheader($stream,$msg_num,$flags);
}
function fetchheader($stream,$msg_num,$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & FT_UID)) )
{
$flags |= FT_UID;
}
return imap_fetchheader($stream,$msg_num,$flags);
}
function fetchstructure($stream,$msg_num,$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & FT_UID)) )
{
$flags |= FT_UID;
}
return imap_fetchstructure($stream,$msg_num,$flags);
}
function get_body($stream,$msg_num,$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & FT_UID)) )
{
$flags |= FT_UID;
}
return imap_body($stream,$msg_num,$flags);
}
function get_header($stream,$msg_num,$flags)
{
// alias for compatibility with some old code
return $this->fetchheader($stream,$msg_num,$flags);
}
function listmailbox($stream,$ref,$pattern)
{
//return imap_listmailbox($stream,$ref,$pattern);
$pattern = $this->utf7_encode($pattern);
$return_list = imap_listmailbox($stream,$ref,$pattern);
return $this->utf7_decode($return_list);
}
function mailboxmsginfo($stream)
{
return imap_mailboxmsginfo($stream);
}
function mailcopy($stream,$msg_list,$mailbox,$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & CP_UID)) )
{
$flags |= CP_UID;
}
$mailbox = $this->utf7_encode($mailbox);
return imap_mail_copy($stream,$msg_list,$mailbox,$flags);
}
function move($stream,$msg_list,$mailbox,$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & CP_UID)) )
{
$flags |= CP_UID;
}
$mailbox = $this->utf7_encode($mailbox);
return imap_mail_move($stream,$msg_list,$mailbox,$flags);
}
function num_msg($stream) // returns number of messages in the mailbox
{
return imap_num_msg($stream);
}
function noop_ping_test($stream)
{
return imap_ping($stream);
}
function open($mailbox,$username,$password,$flags=0)
{
$mailbox = $this->utf7_encode($mailbox);
return imap_open($mailbox,$username,$password,$flags);
}
function qprint($message)
{
// return quoted_printable_decode($message);
$str = quoted_printable_decode($message);
return str_replace("=\n",'',$str);
}
function reopen($stream,$mailbox,$flags=0)
{
$mailbox = $this->utf7_encode($mailbox);
return imap_reopen($stream,$mailbox,$flags);
}
function server_last_error()
{
// supported in PHP >= 3.0.12
return imap_last_error();
}
function i_search($stream,$criteria,$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & SE_UID)) )
{
$flags |= SE_UID;
}
return imap_search($stream,$criteria,$flags);
}
function sort($stream,$criteria,$reverse='',$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & SE_UID)) )
{
$flags |= SE_UID;
}
//echo 'class dcom: sort: $this->force_msg_uids= '.serialize($this->force_msg_uids).'; $flags: ['.serialize($flags).']<br>';
return imap_sort($stream,$criteria,$reverse,$flags);
}
function status($stream,$mailbox,$options=0)
{
$mailbox = $this->utf7_encode($mailbox);
return imap_status($stream,$mailbox,$options);
}
function construct_folder_str($folder)
{
/* This is only used by the login() function */
// Cyrus style: INBOX.Junque
// UWash style: ./aeromail/Junque
return $GLOBALS['phpgw']->msg->get_folder_long($folder);
}
function deconstruct_folder_str($folder)
{
// This is only used by the login() function
// Cyrus style: INBOX.Junque
// UWash style: ./aeromail/Junque
return $GLOBALS['phpgw']->msg->get_folder_short($folder);
}
/* rfc_get_flag() is more "rfc safe", as RFC822 allows
the content of the header to be on several lines.
Quote from RFC822 3.1.1:
<quote>
For convenience, the field-body portion of this conceptual
entity can be split into a multiple-line representation; this
is called "folding". The general rule is that wherever there
may be linear-white-space (NOT simply LWSP-chars), a CRLF
immediately followed by AT LEAST one LWSP-char may instead be
inserted.
</quote>
Note: $flag should _NOT_ begin with a space
$field_no should be given strarting at 1
*/
function get_flag($stream,$msg_num,$flags=0,$field_no=1)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & FT_UID)) )
{
$flags |= FT_UID;
}
$fieldCount = 0;
$header = imap_fetchheader ($stream, $msg_num, $flags);
$header = explode("\n", $header);
$flag = strtolower($flag);
for ($i=0; $i < count($header); $i++)
{
// The next check for the $flag _requires_ the field to
// start at the first character (unless some person
// adds a space in the beginning of $flag.
// I believe this is correct according to the RFC.
if (strcmp (substr(strtolower($header[$i]),0,strlen($flag) + 1), $flag.':')==0)
{
$fieldFound = true;
$fieldCount++;
}
else
{
$fieldFound = false;
}
if ($fieldFound && $fieldCount == $field_no)
{
// We now need to see if the next lines belong to this message.
$header_begin = $i;
// make sure we don't go too far:)
// and if the line begins with a space then
// we'll increment the counter with one.
$i++;
while ($i < count($header)
&& strcmp(substr($header[$i],0,1), ' ') == 0)
{
$i++;
}
// Remove the "field:" from this string.
$return_tmp = explode (':', $header[$header_begin]);
$tmp_flag = $return_tmp[0];
$return_string = trim ($return_tmp[1]);
if (strcasecmp ($flag, $tmp_flag) != 0)
{
return false;
}
// Houston, we have a _problem_
// add the rest of the content
for ($j=$header_begin+1; $j < $i; $j++)
{
$return_string .= $header[$j];
}
return $return_string;
}
}
// failed to find $flag
return false;
}
}
?>

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,208 @@
<?php
/**************************************************************************\
* phpGroupWare Email - POP3 Mail Wrapper for Imap Enabled PHP *
* http://www.phpgroupware.org/ * *
* -------------------------------------------------------------------------*
* This library is part of phpGroupWare (http://www.phpgroupware.org) *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, *
* or any later version. *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/
/* $Id$ */
class msg extends msg_base
{
function base64($text)
{
return imap_base64($text);
}
function close($stream,$flags='')
{
return imap_close($stream,$flags);
}
function createmailbox($stream,$mailbox)
{
// N/A for pop3
return true;
}
function deletemailbox($stream,$mailbox)
{
// N/A for pop3
return true;
}
function delete($stream,$msg_num,$flags='',$currentfolder='')
{
return imap_delete($stream,$msg_num);
}
function expunge($stream)
{
// N/A for pop3
return true;
}
function fetchbody($stream,$msgnr,$partnr,$flags='')
{
return imap_fetchbody($stream,$msgnr,$partnr,$flags);
}
function header($stream,$msg_nr,$fromlength='',$tolength='',$defaulthost='')
{
return imap_header($stream,$msg_nr,$fromlength,$tolength,$defaulthost);
}
function fetch_raw_mail($stream,$msg_num)
{
return imap_fetchheader($stream,$msg_num,FT_PREFETCHTEXT);
}
function fetchheader($stream,$msg_num)
{
return imap_fetchheader($stream,$msg_num);
}
function get_header($stream,$msg_num)
{
// alias for compatibility with some old code
return $this->fetchheader($stream,$msg_num);
}
function fetchstructure($stream,$msg_num,$flags='')
{
return imap_fetchstructure($stream,$msg_num);
}
function get_body($stream,$msg_num,$flags='')
{
return imap_body($stream,$msg_num,$flags);
}
function listmailbox($stream,$ref,$pattern)
{
// N/A for pop3
return False;
}
function num_msg($stream) // returns number of messages in the mailbox
{
return imap_num_msg($stream);
}
function mailboxmsginfo($stream)
{
return imap_mailboxmsginfo($stream);
}
function mailcopy($stream,$msg_list,$mailbox,$flags)
{
// N/A for pop3
return False;
}
function move($stream,$msg_list,$mailbox)
{
// N/A for pop3
return False;
}
function open($mailbox,$username,$password,$flags='')
{
return imap_open($mailbox,$username,$password,$flags);
}
function qprint($message)
{
// return quoted_printable_decode($message);
$str = quoted_printable_decode($message);
return str_replace("=\n",'',$str);
}
function reopen($stream,$mailbox,$flags='')
{
// N/A for pop3
return False;
}
function sort($stream,$criteria,$reverse='',$options='',$msg_info='')
{
return imap_sort($stream,$criteria,$reverse,$options);
}
function status($stream,$mailbox,$options)
{
return imap_status($stream,$mailbox,$options);
//return imap_num_recent($stream);
}
function append($stream,$folder='Sent',$header,$body,$flags='')
{
// N/A for pop3
return False;
}
function login($folder='INBOX')
{
//$debug_logins = True;
$debug_logins = False;
if($debug_logins)
{
echo 'CALL TO LOGIN IN CLASS MSG POP3'.'<br>'.'userid='.$GLOBALS['phpgw_info']['user']['preferences']['email']['userid'];
}
error_reporting(error_reporting() - 2);
if($folder!='INBOX')
{
// pop3 has only 1 "folder" - inbox
$folder='INBOX';
}
// WORKAROUND FOR BUG IN EMAIL CUSTOM PASSWORDS (PHASED OUT 7/2/01)
// $pass = $this->get_email_passwd();
// === ISSET CHECK ==
if ( (isset($GLOBALS['phpgw_info']['user']['preferences']['email']['userid']))
&& ($GLOBALS['phpgw_info']['user']['preferences']['email']['userid'] != '')
&& (isset($GLOBALS['phpgw_info']['user']['preferences']['email']['passwd']))
&& ($GLOBALS['phpgw_info']['user']['preferences']['email']['passwd'] != '') )
{
$user = $GLOBALS['phpgw_info']['user']['preferences']['email']['userid'];
$pass = $GLOBALS['phpgw_info']['user']['preferences']['email']['passwd'];
}
else
{
// problem - invalid or nonexistant info for userid and/or passwd
return False;
}
$server_str = $GLOBALS['phpgw']->msg->get_mailsvr_callstr();
$mbox = $this->open($server_str.$folder, $user, $pass);
error_reporting(error_reporting() + 2);
return $mbox;
}
function construct_folder_str($folder)
{
$folder_str = $GLOBALS['phpgw']->msg->get_folder_long($folder);
return $folder_str;
}
function deconstruct_folder_str($folder)
{
$folder_str = $GLOBALS['phpgw']->msg->get_folder_short($folder);
return $folder_str;
}
} // end of class msg

View File

@ -0,0 +1,324 @@
<?php
/**************************************************************************\
* phpGroupWare API - NNTP *
* This file written by Mark Peters <skeeter@phpgroupware.org> *
* Handles specific operations in dealing with NNTP *
* Copyright (C) 2001 Mark Peters *
* -------------------------------------------------------------------------*
* This library is part of the phpGroupWare API *
* http://www.phpgroupware.org/api *
* ------------------------------------------------------------------------ *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, *
* or any later version. *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/
class msg extends msg_base
{
var $db;
var $folder;
var $start_msg;
var $end_msg;
function mode_reader()
{
return $this->msg2socket('mode reader','^20[01]',&$response);
}
function login ($user,$passwd,$server,$port,$folder = '')
{
global $phpgw;
$this->db = $phpgw->db;
if(@!$server)
{
echo 'Error: Configuration Error! The administrator has not configured the NNTP Server.';
}
if(@!$port)
{
$port = 119;
}
if (!$this->open_port($server,$port,15))
{
$this->error();
}
$this->read_port();
if ($user <> '' && $passwd <> '')
{
if (!$this->msg2socket('authinfo user '.$user,'^381',&$response))
{
$this->error();
}
if (!$this->msg2socket('authinfo pass '.$passwd,'^281',&$response))
{
$this->error();
}
}
if (!$this->mode_reader())
{
$this->error();
}
if(!$folder)
{
$folder = $this->get_first_folder();
if(!$folder)
{
$this->error();
}
}
$this->folder = $folder;
$this->mailbox = $this->get_mailbox_name($folder);
$this->num_msgs = $this->num_msg($this->mailbox);
$this->start_msg = $this->first_message($this->mailbox);
$this->end_msg = $this->last_message($this->mailbox);
echo 'Successful connection to '.$this->mailbox."<br>\n";
}
function fix_folder($folder='')
{
if($folder=='')
{
$mailbox = $this->mailbox;
}
elseif(is_int($folder))
{
$mailbox = $this->get_mailbox_name($folder);
}
else
{
$mailbox = $folder;
}
return $mailbox;
}
function get_first_folder()
{
if(@!$GLOBALS['phpgw_info']['user']['preferences']['nntp'])
{
$this->set_error('Configuration','User Preferences','You have not set your user preferences in NNTP.');
$this->error();
}
else
{
$pref = @each($GLOBALS['phpgw_info']['user']['preferences']['nntp']);
return $pref[0];
}
}
function get_mailbox_name($folder)
{
$active = False;
$this->db->query('SELECT name,active FROM newsgroups WHERE con='.$folder,_LINE__,__FILE__);
if ($this->db->num_rows() > 0)
{
$this->db->next_record();
$mailbox = $this->db->f('name');
}
if ($this->db->f('active') != 'Y')
{
$GLOBALS['phpgw']->preferences->delete('nntp',$folder);
$GLOBALS['phpgw']->preferences->save_repository();
$this->set_error('Administration','Automatic Disabling','The newsgroup '.$mailbox.' is not activated by the Administrator.');
$this->error();
}
return $mailbox;
}
function get_mailbox_counts($folder='',$index=1)
{
$mailbox = $this->fix_folder($folder);
if (!$this->msg2socket('group '.$mailbox,'^211',&$response))
{
$this->error();
}
$temp_array = explode(' ',$response);
return $temp_array[$index];
}
function num_msg($folder='')
{
if(($folder == '' || $folder == $this->mailbox) && isset($this->num_msgs))
{
return $this->num_msgs;
}
return $this->get_mailbox_counts($folder,1);
}
function first_message($folder='')
{
if(($folder == '' || $folder == $this->mailbox) && isset($this->start_msg))
{
return $this->start_msg;
}
return $this->get_mailbox_counts($folder,2);
}
function last_message($folder='')
{
if(($folder == '' || $folder == $this->mailbox) && isset($this->end_msg))
{
return $this->end_msg;
}
return $this->get_mailbox_counts($folder,3);
}
function mailboxmsginfo($folder='')
{
$info = new msg_mb_info;
if($folder=='' || $folder==$this->mailbox || $folder==$this->folder)
{
if(isset($this->num_msgs))
{
$info->messages = $this->num_msgs;
}
else
{
if($folder==$this->folder)
{
$this->mailbox = $this->get_mailbox_name($folder);
}
$info->messages = $this->num_msg($this->mailbox);
}
$info->size = 0;
if ($info->messages)
{
return $info;
}
else
{
return False;
}
}
else
{
$mailbox = $this->fix_folder($folder);
}
$info->messages = $this->num_msgs($mailbox);
$info->size = 0;
$this->num_msgs($this->mailbox);
if ($info->messages)
{
return $info;
}
else
{
return False;
}
}
function fetch_field($start,$stop,$element)
{
if (!$this->msg2socket('XHDR '.$element.' '.$start.'-'.$stop,'^221',&$response))
{
$this->error();
}
$field_element = Array();
while ($line = $this->read_port())
{
$line = chop($line);
if ($line == '.')
{
break;
}
$breakpos = strpos($line,' ');
$field_element[intval(substr($line,0,$breakpos-1))] = $this->phpGW_quoted_printable_decode2(substr($line,$breakpos+1));
}
return $field_element;
}
function status($folder='',$options=SA_ALL)
{
$info = new mailbox_status;
$info->messages = $this->num_msg($folder);
return $info;
}
function sort($folder='',$criteria=SORTDATE,$reverse=False,$options='')
{
if($folder == '' || $folder == $this->mailbox)
{
$mailbox = $this->mailbox;
$start_msg = $this->start_msg;
$end_msg = $this->end_msg;
}
else
{
$mailbox = $this->fix_folder($folder);
$start_msg = $this->first_message($mailbox);
$end_msg = $this->last_message($mailbox);
}
switch($criteria)
{
case SORTDATE:
$old_list = $this->fetch_field($start_msg,$end_msg,'Date');
$field_list = $this->convert_date_array($old_list);
break;
case SORTARRIVAL:
break;
case SORTFROM:
$field_list = $this->fetch_field($start_msg,$end_msg,'From');
break;
case SORTSUBJECT:
$field_list = $this->fetch_field($start_msg,$end_msg,'Subject');
break;
case SORTTO:
$field_list = $this->fetch_field($start_msg,$end_msg,'To');
break;
case SORTCC:
$field_list = $this->fetch_field($start_msg,$end_msg,'cc');
break;
case SORTSIZE:
break;
}
@reset($field_list);
if($criteria == SORTSUBJECT)
{
if(!$reverse)
{
uasort($field_list,array($this,"ssort_ascending"));
}
else
{
uasort($field_list,array($this,"ssort_decending"));
}
}
elseif(!$reverse)
{
asort($field_list);
}
else
{
arsort($field_list);
}
$return_array = Array();
@reset($field_list);
$i = 1;
while(list($key,$value) = each($field_list))
{
$return_array[] = $key;
echo '('.$i++.') Field: <b>'.$value."</b>\t\tMsg Num: <b>".$key."</b><br>\n";
}
@reset($return_array);
return $return_array;
}
}
?>

View File

@ -0,0 +1,252 @@
<?php
/**************************************************************************\
* phpGroupWare Email - POP3 Mail Wrapper for Imap Enabled PHP *
* http://www.phpgroupware.org/ * *
* -------------------------------------------------------------------------*
* This library is part of phpGroupWare (http://www.phpgroupware.org) *
* This library is free software; you can redistribute it and/or modify it *
* under the terms of the GNU Lesser General Public License as published by *
* the Free Software Foundation; either version 2.1 of the License, *
* or any later version. *
* This library is distributed in the hope that it will be useful, but *
* WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
* See the GNU Lesser General Public License for more details. *
* You should have received a copy of the GNU Lesser General Public License *
* along with this library; if not, write to the Free Software Foundation, *
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *
\**************************************************************************/
/* $Id$ */
class msg extends msg_base
{
function append($stream, $folder = 'Sent', $header, $body, $flags=0)
{
// N/A for pop3
return False;
}
function base64($text)
{
return imap_base64($text);
}
function close($stream,$flags=0)
{
return imap_close($stream,$flags);
}
function createmailbox($stream,$mailbox)
{
// N/A for pop3
return true;
}
function deletemailbox($stream,$mailbox)
{
// N/A for pop3
return true;
}
function delete($stream,$msg_num,$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & FT_UID)) )
{
$flags |= FT_UID;
}
$retval = imap_delete($stream,$msg_num,$flags);
imap_expunge($stream);
return $retval;
}
function expunge($stream)
{
// N/A for pop3
return true;
}
function fetchbody($stream,$msgnr,$partnr,$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & FT_UID)) )
{
$flags |= FT_UID;
}
return imap_fetchbody($stream,$msgnr,$partnr,$flags);
}
function fetchheader($stream,$msg_num,$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & FT_UID)) )
{
$flags |= FT_UID;
}
return imap_fetchheader($stream,$msg_num,$flags);
}
function fetch_raw_mail($stream,$msg_num,$flags=0)
{
$flags |= FT_PREFETCHTEXT;
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & FT_UID)) )
{
$flags |= FT_UID;
}
return imap_fetchheader($stream,$msg_num,$flags);
}
function fetchstructure($stream,$msg_num,$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & FT_UID)) )
{
$flags |= FT_UID;
}
return imap_fetchstructure($stream,$msg_num,$flags);
}
function get_body($stream,$msg_num,$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & FT_UID)) )
{
$flags |= FT_UID;
}
return imap_body($stream,$msg_num,$flags);
}
function get_header($stream,$msg_num,$flags)
{
// alias for compatibility with some old code
return $this->fetchheader($stream,$msg_num,$flags);
}
function header($stream,$msg_nr,$fromlength='',$tolength='',$defaulthost='')
{
// do we need to temporarily switch to regular msg num sequence for this function?
if ($this->force_msg_uids == True)
{
// this function can nothandle UIDs, switch to sequence number
$new_msg_nr = imap_msgno($stream,$msg_nr);
if ($new_msg_nr)
{
$msg_nr = $new_msg_nr;
}
}
return imap_header($stream,$msg_nr,$fromlength,$tolength,$defaulthost);
}
function listmailbox($stream,$ref,$pattern)
{
// N/A for pop3
return False;
}
function mailboxmsginfo($stream)
{
return imap_mailboxmsginfo($stream);
}
function mailcopy($stream,$msg_list,$mailbox,$flags)
{
// N/A for pop3
return False;
}
function move($stream,$msg_list,$mailbox,$flags)
{
// N/A for pop3
return False;
}
function num_msg($stream) // returns number of messages in the mailbox
{
return imap_num_msg($stream);
}
function noop_ping_test($stream)
{
return imap_ping($stream);
}
function open($mailbox,$username,$password,$flags=0)
{
return imap_open($mailbox,$username,$password,$flags);
}
function qprint($message)
{
// return quoted_printable_decode($message);
$str = quoted_printable_decode($message);
return str_replace("=\n",'',$str);
}
function reopen($stream,$mailbox,$flags='')
{
// N/A for pop3
return False;
}
function server_last_error()
{
// supported in PHP >= 3.0.12
//UNKNOWN if POP3 server errors also get put here
return imap_last_error();
}
// does this work for pop3?
function i_search($stream,$criteria,$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & SE_UID)) )
{
$flags |= SE_UID;
}
return imap_search($stream,$criteria,$flags);
}
//function sort($stream,$criteria,$reverse='',$options='',$msg_info='')
function sort($stream,$criteria,$reverse='',$flags=0)
{
// do we force use of msg UID's
if ( ($this->force_msg_uids == True)
&& (!($flags & SE_UID)) )
{
$flags |= SE_UID;
}
return imap_sort($stream,$criteria,$reverse,$flags);
}
function status($stream,$mailbox,$options)
{
// don't forget pop3 has 1 "folder": INBOX, any other folder name will not work
return imap_status($stream,$mailbox,$options);
}
function construct_folder_str($folder)
{
// pop3 has only 1 "folder" - inbox
$folder = 'INBOX';
$folder_str = $GLOBALS['phpgw']->msg->get_folder_long($folder);
return $folder_str;
}
function deconstruct_folder_str($folder)
{
// pop3 has only 1 "folder" - inbox
$folder = 'INBOX';
$folder_str = $GLOBALS['phpgw']->msg->get_folder_short($folder);
return $folder_str;
}
} // end of class msg

File diff suppressed because it is too large Load Diff

View File

@ -4,7 +4,7 @@
* This file written by Dan Kuykendall <seek3r@phpgroupware.org> *
* and Joseph Engo <jengo@phpgroupware.org> *
* Has a few functions, but primary role is to load the phpgwapi *
* Copyright (C) 2000, 2001 Dan Kuykendall *
* Copyright (C) 2000, 2001, 2002 Dan Kuykendall *
* -------------------------------------------------------------------------*
* This library is part of the phpGroupWare API *
* http://www.phpgroupware.org/api *