Synchronize the recycle bin of ClawsMail to the mail server

Source: Internet
Author: User
Tags imap
Gmail is still very popular, and there is no way to do it, so you have to get a client to use it. At least it is convenient to use it at work, so you don't have to wait and try again. My usage mode is complex and simple description is as follows: My Work mailbox is mainly accessed from the Web and Mutt client, mainly used for searching and browsing, and archive. All emails are automatically forwarded

Gmail is still very popular, and there is no way to do it, so you have to get a client to use it. At least it is convenient to use it at work, so you don't have to wait and try again. My usage mode is complex and simple description is as follows: My Work mailbox is mainly accessed from the Web and Mutt client, mainly used for searching and browsing, and archive. All emails are automatically forwarded

Gmail is still very popular, and there is no way to do it, so you have to get a client to use it. At least it is convenient to use it at work, so you don't have to wait and try again.

My usage mode is complex and simple description is as follows: My Work mailbox is mainly accessed from the Web and Mutt client, mainly used for searching and browsing, and archive. All emails are automatically forwarded to other personal mailboxes, which are downloaded from the Claws Mail client and managed locally. In daily work, the client of the personal mailbox is the primary, and the Web interface of the Work mailbox is supplemented.

The problem solved in this article is that after deleting emails in the Claws Mail client, these emails are also deleted to the recycle bin in the preceding two mailboxes. It is used to process some junk emails and identify normal emails that are no longer needed.

If you use the IMAP client for management, the same effect can be achieved, but I have a large number of emails, IMAP is too slow, and thousands of mail messages will be refreshed if they are not moved.

Idle talk, next to deal with ideas and some experience, hope to directly find the results please slam the imap-del-for-mh.php, the runtime environment needs to contain Fwlib.

  1. Locate the email file

    Claws Mail uses the MH format to store emails. An email corresponds to a file, and a directory corresponds to a directory in Claws Mail. The structure is very clear.

  2. Connect to the email server

    Because all emails have been downloaded using POP3, you can only connect them using IMAP (otherwise, no emails are listed ). I can't say it's easy to connect to Gmail, But it's acceptable.

  3. Parse the mail file to find the necessary information for locating the mail on the server

    Read files and use regular expressions. The time used to search for emails in IMAP isD M-Y, Minus signs can be omitted, such11-might-2013Or11 May 2013. From and Subject may contain non-English characters and need to be transcoded. The Message-ID should be the unique identifier of the email, but the IMAP server cannot retrieve the email based on it, not because it contains some privacy information.

  4. First search and compare emails

    Because IMAP does not provide an accurate method for searching and locating emails, you can only search for emails based on various conditions, and then block the check Message-ID to check whether it is consistent with that in the local mail file.

    The first time you used the From sender and Date email time to search for the email, you tried to use the Subject mail title. However, you may not be able to find the mail title, probably because you cannot perform fuzzy match based on the Chinese characters. From is also used only<>More accurate. Date search conditions are a little troublesome.ON dateMethod, but it cannot be used.SINCE [previous day] BEFORE [next day]. No matter how you retrieve the email, you cannot find the minimum result set containing the specified email.

    This method can match most normal emails.

  5. The second query and comparison email

    Some abnormal emails, especially spam emails, have strange problems such as incomplete information and incorrect time. If they are not found for the first time, re-query them by changing the conditions. This time, the Recieved receiving time in the mail header is used. This is the time when the mail server receives the email and uses this time as the benchmark, search for emails one by one within the range of the previous day and the next day. Although the speed is slower, all emails can be found in this way theoretically.

  6. Delete email

    After the email is accurately located by Message-ID matching, the UID of the email is obtained. UID and msgid are different. msgid is the serial number in a directory or list, and UID is the unique ID of the email in IMAP. However, when the email is deleted to the recycle bin and restored from the recycle bin, the UID will change.

    Gmail's IMAP delete operations have different meanings from general "delete" operations. They just remove emails from Inbox and run them into All Mails. Therefore, they move emails to the trash directory first, then perform the delete operation, and finally execute the expunge operation.

In the end, if you read all the mail headers at one time and correspond to the local Message-ID, the overall efficiency will be improved if you need to process a large number of emails, but it is not applicable to my scenario.

If IMAP can directly use Message-ID for exact match, it is much easier.

-EOT-

I have been busy with chatting.

Reference
  • Deleting messages with php imap and Gmail

Zemanta

Original article address: Synchronize the recycle bin of Claws Mail to the Mail server. Thank you for sharing it with the original author.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.