Skip to content
Snippets Groups Projects
Commit 0405136f authored by Peter Rotich's avatar Peter Rotich
Browse files

Add support for new MailFetcher init

parent 2a35c5a0
No related branches found
No related tags found
No related merge requests found
...@@ -98,6 +98,27 @@ class Email { ...@@ -98,6 +98,27 @@ class Email {
return $this->getHashtable(); return $this->getHashtable();
} }
function getMailAccountInfo() {
/*NOTE: Do not change any of the tags - otherwise mail fetching will fail */
$info = array(
//Mail server info
'host' => $this->ht['mail_host'],
'port' => $this->ht['mail_port'],
'protocol' => $this->ht['mail_protocol'],
'encryption' => $this->ht['mail_encryption'],
'username' => $this->ht['userid'],
'password' => Mcrypt::decrypt($this->ht['userpass'], SECRET_SALT),
//osTicket specific
'email_id' => $this->getId(), //Required for email routing to work.
'max_fetch' => $this->ht['mail_fetchmax'],
'delete_mail' => $this->ht['mail_delete'],
'archive_folder' => $this->ht['mail_archivefolder']
);
return $info;
}
function isSMTPEnabled() { function isSMTPEnabled() {
return $this->ht['smtp_active']; return $this->ht['smtp_active'];
} }
...@@ -106,17 +127,15 @@ class Email { ...@@ -106,17 +127,15 @@ class Email {
return ($this->ht['smtp_spoofing']); return ($this->ht['smtp_spoofing']);
} }
function getSMTPInfo($active=true) { function getSMTPInfo() {
$info=array();
if(!$active || ($active && $this->isSMTPEnabled())) { $info = array (
'host' => $this->ht['smtp_host'],
$info = array ('host' => $this->ht['smtp_host'], 'port' => $this->ht['smtp_port'],
'port' => $this->ht['smtp_port'], 'auth' => $this->ht['smtp_auth'],
'auth' => $this->ht['smtp_auth'], 'username' => $this->ht['userid'],
'username' => $this->ht['userid'], 'password' => Mcrypt::decrypt($this->ht['userpass'], SECRET_SALT)
'password' =>Mcrypt::decrypt($this->ht['userpass'],SECRET_SALT) );
);
}
return $info; return $info;
} }
...@@ -207,12 +226,12 @@ class Email { ...@@ -207,12 +226,12 @@ class Email {
$vars=$vars; $vars=$vars;
$vars['cpasswd']=$this->getPasswd(); //Current decrypted password. $vars['cpasswd']=$this->getPasswd(); //Current decrypted password.
if($this->save($this->getId(),$vars,$errors)) { if(!$this->save($this->getId(), $vars, $errors))
$this->reload(); return false;
return true;
}
return false; $this->reload();
return true;
} }
...@@ -341,11 +360,8 @@ class Email { ...@@ -341,11 +360,8 @@ class Email {
if(!isset($vars['postfetch'])) if(!isset($vars['postfetch']))
$errors['postfetch']='Indicate what to do with fetched emails'; $errors['postfetch']='Indicate what to do with fetched emails';
elseif(!strcasecmp($vars['postfetch'],'archive')) { elseif(!strcasecmp($vars['postfetch'],'archive') && !$vars['mail_archivefolder'] )
if(!$vars['mail_archivefolder']) $errors['postfetch']='Valid folder required';
$errors['postfetch']='Valid folder required';
}
} }
if($vars['smtp_active']) { if($vars['smtp_active']) {
...@@ -370,10 +386,16 @@ class Email { ...@@ -370,10 +386,16 @@ class Email {
$passwd=$vars['passwd']?$vars['passwd']:$vars['cpasswd']; $passwd=$vars['passwd']?$vars['passwd']:$vars['cpasswd'];
if(!$errors && $vars['mail_active']) { if(!$errors && $vars['mail_active']) {
//note: password is unencrypted at this point...MailFetcher expect plain text. //note: password is unencrypted at this point...MailFetcher expect plain text.
$fetcher = new MailFetcher($vars['userid'],$passwd,$vars['mail_host'],$vars['mail_port'], $fetcher = new MailFetcher(
$vars['mail_protocol'],$vars['mail_encryption']); array(
'host' => $vars['mail_host'],
'port' => $vars['mail_port'],
'username' => $vars['userid'],
'password' => $passwd,
'protocol' => $vars['mail_protocol'],
'encryption' => $vars['mail_encryption'])
);
if(!$fetcher->connect()) { if(!$fetcher->connect()) {
$errors['err']='Invalid login. Check '.Format::htmlchars($vars['mail_protocol']).' settings'; $errors['err']='Invalid login. Check '.Format::htmlchars($vars['mail_protocol']).' settings';
$errors['mail']='<br>'.$fetcher->getLastError(); $errors['mail']='<br>'.$fetcher->getLastError();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment