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

Spam folder UNABLE #110

Open
karado58 opened this issue Aug 21, 2022 · 1 comment
Open

Spam folder UNABLE #110

karado58 opened this issue Aug 21, 2022 · 1 comment

Comments

@karado58
Copy link

There is only one folder Yahoo Mail Server doesn't accept a select box request for, it's the SPAM folder.
imap.select("Spam")

Any workaround for this?!

LL

@x4nth055
Copy link
Owner

Hey @karado58 ,

Sorry for not responding earlier.

Yes, you're right. Yahoo Mail's IMAP server does not allow direct selection of the Spam folder through the typical SELECT command due to its unique handling of spam messages. However, you can use the search functionality to fetch messages from the Spam folder as a workaround.

Here's an example in Python using the imaplib library:

import imaplib

# Replace with your own credentials
email = "your_email@yahoo.com"
password = "your_password"

# Connect to the IMAP server and login
imap_server = imaplib.IMAP4_SSL("imap.mail.yahoo.com", 993)
imap_server.login(email, password)

# Search for all messages in the Spam folder
status, message_numbers = imap_server.search(None, 'X-YMAIL-BOX:Spam')
message_numbers_list = message_numbers[0].split()

# Fetch and process messages
for msg_num in message_numbers_list:
    # Replace 'BODY[]' with 'BODY[HEADER.FIELDS (FROM TO SUBJECT DATE)]' if you only want specific headers
    status, msg_data = imap_server.fetch(msg_num, '(BODY[])')
    
    # Do something with msg_data, e.g., print or save the message

# Logout and close the connection
imap_server.logout()

This script connects to the Yahoo Mail IMAP server, logs in, and searches for messages in the Spam folder. You can then fetch and process the messages as needed. Remember to replace the email and password placeholders with your own Yahoo Mail credentials.

Note that the 'X-YMAIL-BOX' search criterion is specific to Yahoo Mail and may not work with other email providers.

Hope this helps!

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