Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IMAP module not moving mail to folder. #4313

Open
leenooks opened this issue Oct 31, 2024 · 5 comments
Open

IMAP module not moving mail to folder. #4313

leenooks opened this issue Oct 31, 2024 · 5 comments

Comments

@leenooks
Copy link

PHP version: 8.2.20
FreeScout version: 1.8.154
Database: PostgreSQL
Are you using CloudFlare: Yes
Are you using non-official modules: Yes

Hi, I'm using the IMAP Module to move mail to a folder after it has been received/imported into freescout.

The mails stay in the inbox, are marked unread, but are not moved to a folder.

I have tried "Trash", "Archive", "INBOX/Processed" - all folders exist, and are confirmed by the Get Folders on the IMAP folders input.

The log shows this:

[2024-10-31 15:10:04] production.ERROR: [Move or Remove IMAP Message Module] Mailbox: XXX; Message: XXX; Could not move the email to the following IMAP folder: Archive
[2024-10-31 16:45:03] production.ERROR: [Move or Remove IMAP Message Module] Mailbox: XXX; Message: XXX; Could not move the email to the following IMAP folder: INBOX/Processed
@freescout-help
Copy link
Collaborator

Can you send a screenshot of your folders structure (their nesting).

@leenooks
Copy link
Author

image

@leenooks
Copy link
Author

And on the server:
image

@freescout-help
Copy link
Collaborator

You'll need to debug this function: https://github.com/freescout-help-desk/freescout/blob/dist/overrides/webklex/php-imap/src/Message.php#L956

https://github.com/freescout-help-desk/freescout/wiki/Debugging

Try to replace the move() function with the following code and send us the result from Manage > Logs > App Logs:

    public function move(string $folder_path, bool $expunge = false) {
\Log::error('[Debugging] move() function executed.');
        $this->client->openFolder($folder_path);
\Log::error('[Debugging] openFolder() executed.');
        $status = $this->client->getConnection()->examineFolder($folder_path);
\Log::error('[Debugging] status: '.json_encode($status));
        if (isset($status["uidnext"])) {
            $next_uid = $status["uidnext"];
\Log::error('[Debugging] next_uid: '.$next_uid);
            if ((int)$next_uid <= 0) {
                return null;
            }
            
            /** @var Folder $folder */
            $folder = $this->client->getFolderByPath($folder_path);
\Log::error('[Debugging] folder path: '.($folder->path ?? ''));
            $this->client->openFolder($this->folder_path);
            if ($this->client->getConnection()->moveMessage($folder->path, $this->getSequenceId(), null, $this->sequence === IMAP::ST_UID) == true) {
\Log::error('[Debugging] moveMessage() executed.');
                return $this->fetchNewMail($folder, $next_uid, "moved", $expunge);
            }
        }

        return null;
    }

@leenooks
Copy link
Author

[2024-11-01 09:40:04] production.ERROR: [Debugging] move() function executed.
[2024-11-01 09:40:04] production.ERROR: [Debugging] openFolder() executed.
[2024-11-01 09:40:04] production.ERROR: [Debugging] status: {"flags":[["\\Seen","\\Answered","\\Flagged","\\Deleted","\\Draft","$MDNSent","$Forwarded","$Completed"]],"exists":126,"recent":0,"uidnext":305,"uidvalidity":2030456696}
[2024-11-01 09:40:04] production.ERROR: [Debugging] next_uid: 305
[2024-11-01 09:40:04] production.ERROR: [Debugging] folder path: Trash
[2024-11-01 09:40:04] production.ERROR: [Move or Remove IMAP Message Module] Mailbox: XXX; Message: XXX; Could not move the email to the following IMAP folder: Trash

(In this log, I had set it to move the mail to Trash (which is what I originally wanted) - where it is kept for 30 days before being deleted. Didnt want to use the delete function of your module, as I've already discovered some mails are not coming into freescout completely (a different issue), so need to have the mail kept on the server just in case.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants