New to the forum and new to php in general. As I noted in my introductory post in the Newbie section, I am fairly competent at modifying existing code (Frankensteining it as I prefer to refer to it), but my understanding of php is pretty rudimentary, so I don't always get it right and it takes a lot of trial and error. I've hit a wall on a project and could use some pointers.
I have installed osTicket v1.7.2 on our web server without incident; however, the software is not fully functional because our host doesn't have the imap extension enabled (or even installed) on our web server so the portion of osTicket that accepts e-mails and turns the e-mail message into a support ticket is not working correctly. After a lot of hair pulling and gnashing of teeth, I have determined that replacing the imap functions in the osTicket script with Zend\Mail functionality is the best way to go. I've isolated the two scripts that need to be Frankensteined and have gone through and done the best I can, but it is not working as expected. I've managed to get it to the point where it has stopped throwing a 500 Internal Error and returning just a blank screen, but it won't enable the e-mail fetching because it says I have invalid information. I have independently verified that my information is correct, so apparently there's a problem in the way I have converted the IMAP functions (imap_open, imap_fetchstructure, imap_fetchbody, etc) to Zend\Mail.
I'm attaching two files to this post. One is the original script ([ATTACH]4985[/ATTACH]) and the second is the script as I modified it ([ATTACH]4987[/ATTACH]). I am pretty sure that the problem is in the open function (starting at line 116 in the modified version).
Here are the functions in class.email.php that are referenced by the mailfetch script (function load and function getId aren't referenced in mailfetch, but are called for in function Email and function getMailAccountInfo, respectively, so I included them here):
function Email($id) {
$this->id=0;
$this->load($id);
}
function load($id=0) {
if(!$id && !($id=$this->getId()))
return false;
$sql='SELECT * FROM '.EMAIL_TABLE.' WHERE email_id='.db_input($id);
if(!($res=db_query($sql)) || !db_num_rows($res))
return false;
$this->ht=db_fetch_array($res);
$this->id=$this->ht['email_id'];
$this->address=$this->ht['name']?($this->ht['name'].'<'.$this->ht['email'].'>'):$this->ht['email'];
$this->dept = null;
return true;
}
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' => Crypto::decrypt($this->ht['userpass'], SECRET_SALT, $this->ht['userid']),
//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 getId() {
return $this->id;
}
And here is the part of class.email.php that is called when I try to update the settings to use e-mail fetching and is failing and saying my information is incorrect:
if(!$errors && $vars['mail_active']) {
//note: password is unencrypted at this point...MailFetcher expect plain text.
$fetcher = new MailFetcher(
array(
'host' => $vars['mail_host'],
'port' => $vars['mail_port'],
'username' => $vars['userid'],
'password' => $passwd,
'protocol' => $vars['mail_protocol'],
'encryption' => $vars['mail_encryption'])
);
if(!($fetcher->open)) {
$errors['err']='Invalid login. Check '.Format::htmlchars($vars['mail_protocol']).' settings';
$errors['mail']='<br>'.$fetcher->getLastError();
}elseif($vars['mail_archivefolder'] && !$fetcher->checkMailbox($vars['mail_archivefolder'],true)) {
$errors['postfetch']='Invalid or unknown mail folder! >> '.$fetcher->getLastError().'';
if(!$errors['mail'])
$errors['mail']='Invalid or unknown archive folder!';
}
}
Any direction/assistance you guys can give is super appreciated. I'm totally stumped and have been through it all multiple times trying to figure out what I'm missing and just don't know what else to modify to make the thing work.
class.mailfetch.txt class.zmailfetch.txt