Skip to content
Permalink
Browse files

feature: Fetch From Mail Folder

This feature adds a textbox in the Email configurations that allows you to
configure a specific Folder to fetch from. If no folder is provided the
system will fetch from the INBOX as usual. This also adds a check so that if
a Folder is given but doesn't exist and can't be created then the system
will error out with a detailed message.
  • Loading branch information...
JediKev committed Oct 16, 2019
1 parent c2a3d1f commit 901d30a0664705278b8b0a323ad619443d81b60f
@@ -138,6 +138,7 @@ function getMailAccountInfo() {
//osTicket specific
'email_id' => $this->getId(), //Required for email routing to work.
'max_fetch' => $this->mail_fetchmax,
'folder' => $this->mail_folder,
'delete_mail' => $this->mail_delete,
'archive_folder' => $this->mail_archivefolder
);
@@ -250,6 +251,7 @@ function update($vars, &$errors=false) {
$vars['cpasswd']=$this->getPasswd(); //Current decrypted password.
$vars['name']=Format::striptags(trim($vars['name']));
$vars['email']=trim($vars['email']);
$vars['mail_folder']=Format::striptags(trim($vars['mail_folder']));
$id = isset($this->email_id) ? $this->getId() : 0;
if($id && $id!=$vars['id'])
@@ -308,6 +310,9 @@ function update($vars, &$errors=false) {
if(!$vars['mail_fetchmax'] || !is_numeric($vars['mail_fetchmax']))
$errors['mail_fetchmax']=__('Maximum emails required');
if($vars['mail_protocol'] == 'POP' && !empty($vars['mail_folder']))
$errors['mail_folder'] = __('POP mail servers do not support folders');
if(!isset($vars['postfetch']))
$errors['postfetch']=__('Indicate what to do with fetched emails');
elseif(!strcasecmp($vars['postfetch'],'archive')) {
@@ -350,6 +355,7 @@ function update($vars, &$errors=false) {
array(
'host' => $vars['mail_host'],
'port' => $vars['mail_port'],
'folder' => $vars['mail_folder'],
'username' => $vars['userid'],
'password' => $passwd,
'protocol' => $vars['mail_protocol'],
@@ -359,6 +365,10 @@ function update($vars, &$errors=false) {
//$errors['err']='Invalid login. Check '.Format::htmlchars($vars['mail_protocol']).' settings';
$errors['err']=sprintf(__('Invalid login. Check %s settings'),Format::htmlchars($vars['mail_protocol']));
$errors['mail']='<br>'.$fetcher->getLastError();
} elseif ($vars['mail_folder'] && !$fetcher->checkMailbox($vars['mail_folder'],true)) {
$errors['mail_folder']=sprintf(__('Invalid or unknown mail folder! >> %s'),$fetcher->getLastError());
if(!$errors['mail'])
$errors['mail']=__('Invalid or unknown mail folder!');
}elseif($vars['mail_archivefolder'] && !$fetcher->checkMailbox($vars['mail_archivefolder'],true)) {
//$errors['postfetch']='Invalid or unknown mail folder! >> '.$fetcher->getLastError().'';
$errors['postfetch']=sprintf(__('Invalid or unknown mail folder! >> %s'),$fetcher->getLastError());
@@ -400,6 +410,7 @@ function update($vars, &$errors=false) {
$this->userid = $vars['userid'];
$this->mail_active = $vars['mail_active'];
$this->mail_host = $vars['mail_host'];
$this->mail_folder = $vars['mail_folder'] ?: null;
$this->mail_protocol = $vars['mail_protocol'] ?: 'POP';
$this->mail_encryption = $vars['mail_encryption'];
$this->mail_port = $vars['mail_port'] ?: 0;
@@ -126,14 +126,18 @@ function getMaxFetch() {
return $this->ht['max_fetch'];
}
function getMailFolder() {
return $this->mailbox_encode($this->ht['folder'] ?: 'INBOX');
}
function getArchiveFolder() {
return $this->mailbox_encode($this->ht['archive_folder']);
}
/* Core */
function connect() {
return ($this->mbox && $this->ping())?$this->mbox:$this->open();
return ($this->mbox && $this->ping())?$this->mbox:$this->open($this->getMailFolder());
}
function ping() {
@@ -79,6 +79,13 @@ host_and_port:
may be available in the documentation for your hosting account or
from your email administrator.
mail_folder:
title: Mail Folder
content: >
Enter the <span class="doc-desc-title">Folder</span> name that you
wish to fetch mail from. If left emtpy the system will fetch from the
INBOX.
protocol:
title: Mail Box Protocol
content: >
@@ -227,6 +227,16 @@
</span>
</td>
</tr>
<tr><td><?php echo __('Mail Folder'); ?></td>
<td>
<span>
<input type="text" name="mail_folder" size=20 value="<?php echo $info['mail_folder']; ?>"
placeholder="INBOX">
&nbsp;<font class="error">&nbsp;<?php echo $errors['mail_folder']; ?></font>
<i class="help-tip icon-question-sign" href="#mail_folder"></i>
</span>
</td>
</tr>
<tr><td><?php echo __('Port Number'); ?></td>
<td><input type="text" name="mail_port" size=6 value="<?php echo $info['mail_port']?$info['mail_port']:''; ?>">
<span>
@@ -277,7 +287,7 @@
<label><input type="radio" name="postfetch" value="archive" <?php echo ($info['postfetch']=='archive')? 'checked="checked"': ''; ?> >
<?php echo __('Move to folder'); ?>:
<input type="text" name="mail_archivefolder" size="20" value="<?php echo $info['mail_archivefolder']; ?>"/></label>
&nbsp;<font class="error"><?php echo $errors['mail_folder']; ?></font>
&nbsp;<font class="error"><?php echo $errors['mail_archivefolder']; ?></font>
<i class="help-tip icon-question-sign" href="#fetched_emails"></i>
<br/>
<label><input type="radio" name="postfetch" value="delete" <?php echo ($info['postfetch']=='delete')? 'checked="checked"': ''; ?> >
@@ -1 +1 @@
cc6d1b03792f91fc3b6bc1d85bdc9813
914098f4a7022c558038471e7f9eec62
@@ -0,0 +1,12 @@
/**
* @signature 914098f4a7022c558038471e7f9eec62
* @version v1.14-rc3
* @title Add mail folder to emails
*
*/
ALTER TABLE `%TABLE_PREFIX%email` ADD `mail_folder` varchar(255) DEFAULT NULL AFTER `mail_encryption`;

-- Finished with patch
UPDATE `%TABLE_PREFIX%config`
SET `value` = '914098f4a7022c558038471e7f9eec62'
WHERE `key` = 'schema_signature' AND `namespace` = 'core';
@@ -252,6 +252,7 @@ CREATE TABLE `%TABLE_PREFIX%email` (
`mail_host` varchar(255) NOT NULL,
`mail_protocol` enum('POP','IMAP') NOT NULL default 'POP',
`mail_encryption` enum('NONE','SSL') NOT NULL,
`mail_folder` varchar(255) default NULL,
`mail_port` int(6) default NULL,
`mail_fetchfreq` tinyint(3) NOT NULL default '5',
`mail_fetchmax` tinyint(4) NOT NULL default '30',

0 comments on commit 901d30a

Please sign in to comment.
You can’t perform that action at this time.