Source for file functions.php
Documentation is available at functions.php
-  * mail_fetch/functions.php 
-  * Functions for the mail_fetch plugin. 
-  * @copyright 1999-2020 The SquirrelMail Project Team 
-  * @license http://opensource.org/licenses/gpl-license.php GNU Public License 
-  * @version $Id: functions.php 14845 2020-01-07 08:09:34Z pdontthink $ 
- include_once (SM_PATH - .  'plugins/mail_fetch/constants.php');
 
- include_once (SM_PATH - .  'plugins/mail_fetch/class.mail_fetch.php');
 
- /** declare plugin globals */ 
- global $mail_fetch_allow_unsubscribed, $mail_fetch_allowable_ports, 
-        $mail_fetch_block_server_pattern; 
-   * Add link to menu at top of content pane 
-     global $oTemplate, $nbsp; 
-     return array('menuline' - =>  $output);
 
-  * Controls use of unsubscribed folders in plugin 
-  * @global boolean $mail_fetch_allow_unsubscribed  
- $mail_fetch_allow_unsubscribed - =  false;
 
-     include_once(SM_PATH - .  'config/mail_fetch_config.php');
 
-     include_once(SM_PATH - .  'plugins/mail_fetch/config.php');
 
-  * Internal function used to fetch pop3 mails on login 
-     include_once (SM_PATH - .  'functions/imap_general.php');
 
-     global $username, $data_dir, $imapServerAddress, $imapPort, $imap_stream_options; 
-     $mailfetch_newlog - =  getPref($data_dir, $username, 'mailfetch_newlog');
 
-     $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_loop- = 0;$i_loop- < $mailfetch_server_number;$i_loop- ++ ) {
 
-         $mailfetch_login_[$i_loop] - =  getPref($data_dir, $username, "mailfetch_login_$i_loop");
 
-         $mailfetch_fref_[$i_loop] - =  getPref($data_dir, $username, "mailfetch_fref_$i_loop");
 
-         $mailfetch_pass_[$i_loop] - =  getPref($data_dir, $username, "mailfetch_pass_$i_loop");
 
-         if( $mailfetch_cypher - ==  'on' ) {
 
-             $mailfetch_pass_[$i_loop] - =  decrypt( $mailfetch_pass_[$i_loop] );
 
-         if( $mailfetch_pass_[$i_loop] - <>  ''- &&           // Empty passwords no allowed
 
-                 ( ( $mailfetch_login_[$i_loop] - ==  'on'- &&   $mailfetch_newlog- ==  'on' )- ||  $mailfetch_fref_[$i_loop]- ==  'on' ) ) {
 
-             $mailfetch_server_[$i_loop] - =  getPref($data_dir, $username, "mailfetch_server_$i_loop");
 
-             $mailfetch_port_[$i_loop] - =  getPref($data_dir, $username , "mailfetch_port_$i_loop");
 
-             $mailfetch_alias_[$i_loop] - =  getPref($data_dir, $username, "mailfetch_alias_$i_loop");
 
-             $mailfetch_user_[$i_loop] - =  getPref($data_dir, $username, "mailfetch_user_$i_loop");
 
-             $mailfetch_lmos_[$i_loop] - =  getPref($data_dir, $username, "mailfetch_lmos_$i_loop");
 
-             $mailfetch_uidl_[$i_loop] - =  getPref($data_dir, $username, "mailfetch_uidl_$i_loop");
 
-             $mailfetch_subfolder_[$i_loop] - =  getPref($data_dir, $username, "mailfetch_subfolder_$i_loop");
 
-             $mailfetch_server- = $mailfetch_server_[$i_loop];
 
-             $mailfetch_port- = $mailfetch_port_[$i_loop];
 
-             $mailfetch_user- = $mailfetch_user_[$i_loop];
 
-             $mailfetch_alias- = $mailfetch_alias_[$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];
 
-             $mailfetch_auth- = $mailfetch_auth_[$i_loop];
 
-             $mailfetch_type- = $mailfetch_type_[$i_loop];
 
-             // $outMsg .= "$mailfetch_alias checked<br />"; 
-             // $outMsg .= "$mailfetch_alias_[$i_loop]<br />"; 
-             // FIXME: duplicate code with different output destination. 
-             $pop3 - =  new mail_fetch(array('host'- =>  $mailfetch_server,
 
-                                          'port'    - =>  $mailfetch_port,
 
-                                          'auth'    - =>  $mailfetch_auth,
 
-                                          'tls'     - =>  $mailfetch_type,
 
-             if (!empty($pop3->error)) { 
-                 $outMsg - .=  _("Warning:")- .  ' '- .  $pop3->error;
 
-             $imap_stream - =  sqimap_login($username, false, $imapServerAddress, $imapPort, 10, $imap_stream_options);
 
-             if (! $pop3->login($mailfetch_user, $mailfetch_pass)) { 
-                 $outMsg - .=  _("Login Failed:")- .  ' '- .  $pop3->error;
 
-             $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();
 
-             for (; $i - <=  $Count; $i- ++ ) {
 
-                 $Message - =  $pop3->command_retr($i);
 
-                 // check if mail folder is not null and subscribed (There is possible issue with /noselect mail folders) 
-                 if ($mailfetch_subfolder- == ''- || 
 
-                     fputs($imap_stream, "A3$i APPEND INBOX {" - .  strlen($Message)- .  "}\r\n");
 
-                     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"); 
-                     // Check results of append command 
-                         if ($mailfetch_lmos - ==  'on') {
 
-                             setPref($data_dir,$username,"mailfetch_uidl_$i_loop", $msglist[$i- - 1]);
 
-                         // Destroy msg list in order to prevent UIDL update 
-                         // if append fails, don't download other messages 
-                     if ($mailfetch_lmos - !=  'on') {
 
-                     $outMsg - .=  _("Error Appending Message!");
 
-             if ($mailfetch_lmos - ==  'on'- &&  is_array($msglist)) {
 
-     if( trim( $outMsg ) - <>  '' ) {
 
-         echo  '<br /><font size="1">'- .  _("Mail Fetch Result:")- .  "<br />$outMsg</font>";
-     if( $mailfetch_newlog - ==  'on' ) {
 
-         setPref($data_dir, $username, 'mailfetch_newlog', 'off'); 
-  * Internal function used to detect new logins 
-     global $data_dir, $username; 
-     setPref( $data_dir, $username, 'mailfetch_newlog', 'on' ); 
-  * Internal function used to register option block 
-     $optpage_blocks[] - =  array(
 
-             'name' - =>  _("POP3 Fetch Mail"),
 
-             'url'  - =>  '../plugins/mail_fetch/options.php',
 
-             'desc' - =>  _("This configures settings for downloading email from a POP3 mailbox to your account on this server."),
 
-  * Internal function used to update mail_fetch settings 
-  * when folders are renamed or deleted. 
-     global $username, $data_dir; 
-     /* Should be 3 ars, 1: old folder, 2: action, 3: new folder */ 
-     list ($old_folder, $action, $new_folder)- =  $args;
-     $mailfetch_server_number - =  getPref($data_dir, $username, 'mailfetch_server_number');
 
-     for ($i - =  0; $i- <  $mailfetch_server_number; $i- ++ ) {
 
-         $mailfetch_subfolder - =  getPref($data_dir, $username, 'mailfetch_subfolder_'- .  $i);
 
-         if ($mailfetch_subfolder - !=  $old_folder) {
 
-         if ($action - ==  'delete') {
 
-             setPref($data_dir, $username, 'mailfetch_subfolder_' - .  $i, 'INBOX');
 
-         } elseif ($action - ==  'rename') {
 
-             setPref($data_dir, $username, 'mailfetch_subfolder_' - .  $i, $new_folder);
 
- // end of hooked functions 
-  * hex2bin - convert a hexadecimal string into binary 
-         for( $i- = 0; $i- <  $len; $i- +=  2 ) {
 
-     if( !- isset ( $MF_TIT ) ) {
 
-         $MF_TIT - =  "MailFetch Secure for SquirrelMail 1.x";
 
-     $encrypt_key - =  md5( $MF_TIT );
 
-     for( $i - =  0; $i- <  strlen( $txt ); $i- ++  ) {
 
-         if( $ctr - ==  strlen( $encrypt_key ) ) $ctr- = 0;
 
-         $tmp- .=  substr( $txt, $i, 1 )- ^  substr( $encrypt_key, $ctr, 1 );
 
-     $encrypt_key - =  md5( rand( 0, 32000 ) );
 
-     for( $i - =  0; $i- <  strlen( $txt ); $i- ++  ) {
 
-         if ($ctr- == strlen($encrypt_key)) $ctr- = 0;
 
-         $tmp- .=  substr($encrypt_key,$ctr,1)- . 
 
-     for ( $i- = 0; $i- <  strlen( $txt ); $i- ++  ) {
 
-         $tmp- .=  ( substr( $txt, $i, 1 )- ^  $md5 );
 
-  * @param stream $imap_stream imap connection resource 
-  * @param string $imap_folder imap folder name 
-  * @return boolean true, when folder can be used to store messages. 
-     // check if folder is subscribed or only exists. 
-     // make sure that folder can store messages 
-  * Checks if folder is noselect (can't store messages) 
-  * Function does not check if folder subscribed. 
-  * @param stream $imap_stream imap connection resource 
-  * @param string $imap_folder imap folder name 
-  * @return boolean true, when folder has noselect flag. false in any other case. 
-     foreach($boxes as $box) { 
-         if ($box['unformatted']- == $imap_folder) {
 
-   * Validate a requested POP3 port number 
-   * Allowable port numbers are configured in config.php 
-   * (see config_example.php for an example and more 
-   * rules about how the list of allowable port numbers 
-   * @param int $requested_port The port number given by the user 
-   * @return string An error string is returned if the port 
-   *                 number is not allowable, otherwise an 
-   *                 empty string is returned. 
-     global $mail_fetch_allowable_ports; 
-     if (empty($mail_fetch_allowable_ports)) 
-         $mail_fetch_allowable_ports - =  array(110, 995);
 
-     if (in_array('ALL', $mail_fetch_allowable_ports)) 
-     if (!in_array($requested_port, $mail_fetch_allowable_ports)) { 
-         $error - =  _("Sorry, that port number is not allowed");
 
-   * Validate a requested POP3 server address 
-   * Blocked server addresses are configured in config.php 
-   * (see config_example.php for more details) 
-   * @param int $requested_address The server address given by the user 
-   * @return string An error string is returned if the server 
-   *                 address is not allowable, otherwise an 
-   *                 empty string is returned. 
-     global $mail_fetch_block_server_pattern; 
-     if (empty($mail_fetch_block_server_pattern)) 
-         $mail_fetch_block_server_pattern - =  '/(^10\.)|(^192\.)|(^127\.)|(^localhost)/';
 
-     if ($mail_fetch_block_server_pattern - ==  'UNRESTRICTED')
 
-     if (preg_match($mail_fetch_block_server_pattern, $requested_address)) { 
-         $error - =  _("Sorry, that server address is not allowed");
 
 
	
		Documentation generated on Mon, 13 Jan 2020 04:22:34 +0100 by phpDocumentor 1.4.3