From faf089df105195d290430b7683233205ab84d39e Mon Sep 17 00:00:00 2001
From: Jared Hancock <jared@osticket.com>
Date: Wed, 14 May 2014 16:51:37 -0500
Subject: [PATCH] email: Simplify select of mail box protocol

---
 include/class.email.php     | 7 +++++++
 include/class.mailfetch.php | 9 +++++++++
 include/staff/email.inc.php | 6 ++++++
 3 files changed, 22 insertions(+)

diff --git a/include/class.email.php b/include/class.email.php
index efc4a1260..aa6facef4 100644
--- a/include/class.email.php
+++ b/include/class.email.php
@@ -38,6 +38,10 @@ class Email {
 
 
         $this->ht=db_fetch_array($res);
+        $this->ht['mail_proto'] = $this->ht['mail_protocol'];
+        if ($this->ht['mail_encryption'] == 'SSL')
+            $this->ht['mail_proto'] .= "/".$this->ht['mail_encryption'];
+
         $this->id=$this->ht['email_id'];
         $this->address=$this->ht['name']?($this->ht['name'].'<'.$this->ht['email'].'>'):$this->ht['email'];
 
@@ -261,6 +265,9 @@ class Email {
                 $errors['passwd'] = 'Unable to encrypt password - get technical support';
         }
 
+        list($vars['mail_protocol'], $encryption) = explode('/', $vars['mail_proto']);
+        $vars['mail_encryption'] = $encryption ?: 'NONE';
+
         if($vars['mail_active']) {
             //Check pop/imapinfo only when enabled.
             if(!function_exists('imap_open'))
diff --git a/include/class.mailfetch.php b/include/class.mailfetch.php
index 4e83c6f48..3ab0d891a 100644
--- a/include/class.mailfetch.php
+++ b/include/class.mailfetch.php
@@ -723,6 +723,15 @@ class MailFetcher {
         return $ticket;
     }
 
+    static function getSupportedProtos() {
+        return array(
+            'IMAP/SSL'  => 'IMAP + SSL',
+            'IMAP'      => 'IMAP',
+            'POP/SSL'   => 'POP + SSL',
+            'POP'       => 'POP',
+        );
+    }
+
 
     function fetchEmails() {
 
diff --git a/include/staff/email.inc.php b/include/staff/email.inc.php
index c54ec8085..e8d3a430e 100644
--- a/include/staff/email.inc.php
+++ b/include/staff/email.inc.php
@@ -25,6 +25,12 @@ if($email && $_REQUEST['a']!='add'){
     $info['ispublic']=isset($info['ispublic'])?$info['ispublic']:1;
     $info['ticket_auto_response']=isset($info['ticket_auto_response'])?$info['ticket_auto_response']:1;
     $info['message_auto_response']=isset($info['message_auto_response'])?$info['message_auto_response']:1;
+    if (!$info['mail_fetchfreq'])
+        $info['mail_fetchfreq'] = 5;
+    if (!$info['mail_fetchmax'])
+        $info['mail_fetchmax'] = 10;
+    if (!isset($info['smtp_auth']))
+        $info['smtp_auth'] = 1;
     $qstr.='&a='.$_REQUEST['a'];
 }
 $info=Format::htmlchars(($errors && $_POST)?$_POST:$info);
-- 
GitLab