$mailfetch_login = $mailfetch[$i_loop]['login'];
$mailfetch_uidl = $mailfetch[$i_loop]['uidl'];
$mailfetch_subfolder = $mailfetch[$i_loop]['subfolder'];
- if($mailfetch_subfolder == '') {
- $mailfetch_subfolder == 'INBOX';
- }
$pop3 = new POP3($mailfetch_server, 60);
Mail_Fetch_Status(_("Opening IMAP server"));
$imap_stream = sqimap_login($username, $key, $imapServerAddress, $imapPort, 10);
+ // check if destination folder is not set, is not subscribed and is not \noselect folder
+ if($mailfetch_subfolder == '' ||
+ ! mail_fetch_check_folder($imap_stream,$mailfetch_subfolder)) {
+ $mailfetch_subfolder = 'INBOX';
+ }
+
Mail_Fetch_Status(_("Opening POP server"));
$Count = $pop3->login($mailfetch_user, $mailfetch_pass);
if (($Count == false || $Count == -1) && $pop3->ERROR != '') {
* @subpackage mail_fetch
*/
+/** declare plugin globals */
+global $mail_fetch_allow_unsubscribed;
+
+/**
+ * Controls use of unsubscribed folders in plugin
+ * @global boolean $mail_fetch_allow_unsubscribed
+ * @since 1.5.1
+ */
+$mail_fetch_allow_unsubscribed = false;
+
/**
* hex2bin - document me
*/
return $tmp;
}
+/**
+ * check mail folder
+ * @param stream $imap_stream imap connection resource
+ * @param string $imap_folder imap folder name
+ * @return boolean true, when folder can be used to store messages.
+ * @since 1.5.1
+ */
+function mail_fetch_check_folder($imap_stream,$imap_folder) {
+ global $mail_fetch_allow_unsubscribed;
+
+ // check if folder is subscribed or only exists.
+ if (sqimap_mailbox_is_subscribed($imap_stream,$imap_folder)) {
+ $ret = true;
+ } elseif ($mail_fetch_allow_unsubscribed && sqimap_mailbox_exists($imap_stream,$imap_folder)) {
+ $ret = true;
+ } else {
+ $ret = false;
+ }
+
+ // make sure that folder can store messages
+ if ($ret && mail_fetch_check_noselect($imap_stream,$imap_folder)) {
+ $ret = false;
+ }
+
+ return $ret;
+}
+
+/**
+ * Checks if folder is noselect (can't store messages)
+ *
+ * Function does not check if folder subscribed.
+ * @param stream $imap_stream imap connection resource
+ * @param string $imap_folder imap folder name
+ * @return boolean true, when folder has noselect flag. false in any other case.
+ * @since 1.5.1
+ */
+function mail_fetch_check_noselect($imap_stream,$imap_folder) {
+ $boxes=sqimap_mailbox_list($imap_stream);
+ foreach($boxes as $box) {
+ if ($box['unformatted']==$imap_folder) {
+ return (bool) check_is_noselect($box['raw']);
+ }
+ }
+ return false;
+}
?>
\ No newline at end of file
$squirrelmail_plugin_hooks['login_verified']['mail_fetch'] = 'mail_fetch_setnew';
$squirrelmail_plugin_hooks['left_main_before']['mail_fetch'] = 'mail_fetch_login';
$squirrelmail_plugin_hooks['optpage_register_block']['mail_fetch'] = 'mailfetch_optpage_register_block';
-
+ $squirrelmail_plugin_hooks['rename_or_delete_folder']['mail_fetch'] = 'mail_fetch_folderact';
}
function mail_fetch_link() {
while (list($lineNum, $line) = each ($MessArray)) {
$Message .= $line;
}
-
- if ($mailfetch_subfolder=="") {
+
+ // check if mail folder is not null and subscribed (There is possible issue with /noselect mail folders)
+ if ($mailfetch_subfolder=='' ||
+ ! mail_fetch_check_folder($imap_stream,$mailfetch_subfolder)) {
fputs($imap_stream, "A3$i APPEND INBOX {" . strlen($Message) . "}\r\n");
} else {
fputs($imap_stream, "A3$i APPEND $mailfetch_subfolder {" . strlen($Message) . "}\r\n");
);
}
+function mail_fetch_folderact($args) {
+ global $username, $data_dir;
+
+ if (empty($args) || !is_array($args)) {
+ return;
+ }
+
+ /* Should be 3 ars, 1: old folder, 2: action, 3: new folder */
+ if (count($args) != 3) {
+ return;
+ }
+
+ list($old_folder, $action, $new_folder) = $args;
+
+ $mailfetch_server_number = getPref($data_dir, $username, 'mailfetch_server_number');
+
+ for ($i = 0; $i < $mailfetch_server_number; $i++) {
+ $mailfetch_subfolder = getPref($data_dir, $username, 'mailfetch_subfolder_' . $i);
+
+ if ($mailfetch_subfolder != $old_folder) {
+ continue;
+ }
+
+ if ($action == 'delete') {
+ setPref($data_dir, $username, 'mailfetch_subfolder_' . $i, 'INBOX');
+ } elseif ($action == 'rename') {
+ setPref($data_dir, $username, 'mailfetch_subfolder_' . $i, $new_folder);
+ }
+ }
+}
?>
\ No newline at end of file