How to move ONLY messages that have attachments?

Max

I have the following code moving all emails in a folder to the "Old" folder using Mailbox package:

with MailBox('mail.yu.nl').login('[email protected]', 'yu', initial_folder='INBOX') as mailbox:
    mailbox.move(mailbox.fetch(), 'Inbox.Old') 

Now, I only want to move messages that have attachments in them.

I've tried the following:

 resp, items = imap.uid("search",None, 'All')

resp, data = imap.uid('fetch',msg_uid, "(RFC822)") 

However, with no success..

Please help!

arnt

I'm curious. Why did you think none or all would match only messages with attachments?

As @triplee says, there's no real definition of attachment so you'll have to fix a definition yourself. But you could approximate, and e.g. move all multipart messages, or all messages with image parts, all messages with PDF parts or all messages for which a bodypart has been explicitly labelled as an attachment (which happens now and then). The search keys are, respectively, header content-type multipart, header content-type image/, header content-type application/pdf and header content-disposition attachment.

The first of these four examples will work well, the other three will work with some servers but far from all, because the specification says "…has a header with…", which one may take to mean "among the message headers" or "among either the message headers or the per-part headers". Good luck with your server.

You can also use or to join several of the conditions.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I filter inbox and only download emails that have attachments

How to select records that have attachments

How to properly read the url of attachments from messages?

How do I get ActionMailer to log sent messages but NOT include the attachments?

How to automate saving attachments AND memo writing inside the messages

How to not have console messages on shutdown?

How to register to receive service bus session messages that only have a particular session id?

How to configure RabbitMQ to store only part of messages in RAM (because I have really large queue)

RecyclerView for Messages with Attachments not properly showing attachments

No attachments when reading messages (cannot save attachments)

How to use Akka.Net Cluster to have an entity on only one node and have messages arrive there from all nodes

How do I have a const member move-only object without making my object copyable?

Downloading attachments from unseen messages

Move inline images to attachments with nodemailer

Have a discord bot send many messages with only one command

How to programmatically resend messages that have faulted with EasyNetQ?

When logging deleted messages, how can I log the deleted image attachments reliably?

laravel relationship tickets, ticket messages and message attachments

Forwarding email as inline messages and not as attachments in Thunderbird

PHP email with multiple attachments with text messages

Send messages to Slack with attachments using Python

Apache Artemis: How to move JMS messages to a different queue

How to move past undeserializable messages in Spring Kafka 1.3 with Avro

How to prevent alpine from asking to move read messages?

How I can move messages to another folder in Outlook in python

How to only have one display?

How have differents orientation for multiple attachments when i send mail with apps script?

How can I refresh the XPages File Download Control and have it display updated attachments without full page refresh?

Outlook VBA Scripting – Print Attachments & Move Emails