Search The ForumSearch   RegisterRegister  LoginLogin

AfterLogic WebMail Pro

 AfterLogic Forum : AfterLogic WebMail Pro
Subject Topic: Playing With Light Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
Corwin
Valued Community Member
Valued Community Member
Avatar

Joined: 16 March 2009
Location: Russian Federation
Online Status: Offline
Posts: 15
Posted: 09 March 2010 at 5:21am | IP Logged Quote Corwin

I am going to provide members of my personal community with a webmail interface, and of course I've selected Lite version of AfterLogic WebMail (PHP). Aside from the fact it's free, I don't really need things like multiple identities or calendar, and the only API-related thing I require is present in Lite.

The biggest problem I have at my host is that I am not allowed to use SMTP, I have to stick to standard mail() function of PHP. It was surprisingly simple to modify WebMail Lite so that it uses that function instead of SMTP access. It's necessary to edit only one function found in common\class_smtp.php file:
Code:
function SendMail(&$settings, &$account, &$message, $from, $to)

I didn't even remove its original content, just inserted a block of code at its start:
Code:
             $msg = $message->TryToGetOriginalMailMessage();
             $eml_file = explode("\r\n",$msg);
             $carry = 'yes';
             $headers = array();
             $body = '';
             $ii = -1;
             // For every line, carry out this loop
             foreach($eml_file as $key => $value)
             {
                 if ((trim($value)=="")||($carry=='no'))
                 {
                      // Stop putting data into the $headers array
                      $carry = 'no';
                     $i++;
                      $body .= rtrim($value)."\r\n";
                 }
                 else
                 {   
                      // Separate each one with a colon
                     if(($eml_file_expl = explode(':', $value))&&($carry == 'yes'))
                      {
                          // The row has been split in half at least...
                           if(isset($eml_file_expl[1]))
                          {
                               // Put it into the preliminary headers
                               $headers[$eml_file_expl[0]] = $eml_file_expl[1];
                               // There might be more semicolons in it...
                               for($i=2;$i<=$count;$i++)
                               {
                                   // Add the other values to the header
                                   $headers[$eml_file_expl[0]] .= ':'.$eml_file_expl[$i];
                               }
                           }   
                     }       
                 }
             }
             $eml_values = array();
             $eml_values['to'] = $headers['To'];
             $eml_values['from'] = $headers['From'];
             $eml_values['subject'] = $headers['Subject'];
             $eml_values['reply-to'] = $headers['Reply-To'];
             $eml_values['content-type'] =  $message->Headers->GetHeaderValueByName('Content-Type' );
             $eml_values['content-transfer-encoding'] =  $message->Headers->GetHeaderValueByName('Content-Trans fer-Encoding');
             $eml_values['body'] = $body;
       
             $hdrs='From: '.$headers['From']."\r\n".'Content-Type: '.$eml_values['content-type'];
             if ($eml_values['content-transfer-encoding']!="")
               $hdrs.="\r\nContent-Transfer-Encoding: ".$eml_values['content-transfer-encoding'];
             return (mail($eml_values['to'], $eml_values['subject'], $eml_values['body'], $hdrs));


I have used this tip as a ground of the modification. It's not really optimized yet but it does what it's supposed to do.

I've also added few other modifications to WebMail. In particular, I need Direct Mode to be used with IMAP, and I'm not going to let users change that. So the Manage Folders screen is removed.

1. File js\screen.user-settings.js, line 457:
Code:
        if (mode == 4) {
             div.className = 'wm_settings_switcher_select_item';
             div.innerHTML = Lang.ManageFolders;
        } else {
             div.className = 'wm_settings_switcher_item';


Both classnames are replaced with wm_hide.

2. File js\screen.messages-list.js, line 831:
Code:
    this._manageFolders.className = 'wm_manage_folders';


3. Same file js\screen.messages-list.js, line 1750
Code:
    mf.className = 'wm_manage_folders';


Again, all the classnames are replaced with wm_hide.

Yet another thing removed is the nasty "D" next to folder name in Direct Mode. Commented out a few lines in js\class.screens-parts.js file (line 1354):

Code:
        if (this._syncType == SYNC_TYPE_DIRECT_MODE) {
             innerHtml += ' <span class="wm_folder_direct_mode" title="' + Lang.DirectAccessTitle + '"> ' + Lang.DirectAccess + ' </span>';
        }


I really hope it will help someone else like it helped me!

Cheers,
Corwin.
Back to Top View Corwin's Profile Search for other posts by Corwin Visit Corwin's Homepage
 
Corwin
Valued Community Member
Valued Community Member
Avatar

Joined: 16 March 2009
Location: Russian Federation
Online Status: Offline
Posts: 15
Posted: 09 March 2010 at 11:41am | IP Logged Quote Corwin

Well, I have rewritten the mail() related part completely, and it is much simpler now. Most headers are kept intact, just From and Subject header values retrieved (even multiline ones are fetched fine). Plus, Bcc header should be handled separately. Here's the brand new block of code for SendMail function:
Code:
$msg = $message->TryToGetOriginalMailMessage();
$eml_file = explode("\r\n",$msg);
$is_main = false;
$hdrs=''; $body = ''; $hdr_to=''; $hdr_subj=''; $head_key='';
foreach($eml_file as $key => $value)
{
  if ((!$is_main)&&(trim($value)==""))
    $is_main = true;
  if ($is_main)
    $body .= $value."\r\n";
  else
  {
    $head_val=$value;
    if (($epos=strpos($value,':'))!==false)
    {
      $head_key = substr($value,0,$epos);
      $head_val = substr($value,2+$epos);
    }
    if (($head_key)=='To') $hdr_to.=$head_val."\r\n";
    elseif (($head_key)=='Subject') $hdr_subj.=$head_val."\r\n";
    else $hdrs.=$value."\r\n";
  }
}
if ( ( $hdr_bcc=( $message->Headers->GetHeaderValueByName("BCC") ) ) != "" )
  $hdrs.="Bcc: $hdr_bcc\r\n";
return (mail($hdr_to, $hdr_subj, $body, $hdrs));


Cheers,
Corwin.
Back to Top View Corwin's Profile Search for other posts by Corwin Visit Corwin's Homepage
 
Igor
AfterLogic Support
AfterLogic Support


Joined: 24 June 2008
Location: United States
Online Status: Offline
Posts: 6104
Posted: 16 March 2010 at 4:17am | IP Logged Quote Igor

We have modified your code and have optimized it a bit, it is added into our Knowledge Base now if you don't mind. We're frequently asked of what can user do with SMTP access disabled, and this one should be helpful in such cases.

--
Regards,
Igor, AfterLogic Support
Back to Top View Igor's Profile Search for other posts by Igor
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide