Python Forum
Yahoo email "search and destroy"!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Yahoo email "search and destroy"!
#11
(Aug-27-2022, 04:50 PM)Linh_lee Wrote: I named my script DeleteEmailFiles.py, not imap_tools.py
Ohh sorry i did read a little fast.
Do you have file named mailbox.py?
Search the only one you should have is in folder ...site-packages\imap_tools.
Rename or delete if you have an other mailbox.py

Test import as i said for command line.
>>> from imap_tools import MailBox, A
>>> # no error here

# Can access attributes of MailBox
>>> MailBox.email_message_class
<class 'imap_tools.message.MailMessage'>
Reply
#12
Trying to search/delete for specific user with one letter name, "a", and always changing domains.
Some addresses from this spammer:
Output:
[email protected] [email protected] [email protected]
New error now:

Error:
C:\Users\Desktop\Desktop\Python Spam Buster λ python DeleteEmailFiles.py Traceback (most recent call last): File "C:\Users\Desktop\Desktop\Python Spam Buster\DeleteEmailFiles.py", line 6, in <module> mailbox.delete(mailbox.fetch(A(body='a@*.*'))) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python310\lib\site-packages\imap_tools\mailbox.py", line 176, in delete uid_str = clean_uids(uid_list) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python310\lib\site-packages\imap_tools\utils.py", line 30, in clean_uids raise TypeError('uid "{}" is not string'.format(str(uid))) TypeError: uid "<imap_tools.message.MailMessage object at 0x000002BFFD37BD60>" is not string
Reply
#13
The file in you folder named "imap_tools.py" is what snippsat is talking about. Placing a file with that name in the same folder as "DeleteEmailFiles.py" prevents you from importing the imap_tools module. It was also causing a circular reference because it contained the line:
from imap_tools import MailBox, A 
You can see this reported in the error message:
Error:
File "C:\Users\Desktop\Desktop\Python Spam Buster\imap_tools.py", line 2, in <module> <-- This is a file in your local folder from imap_tools import MailBox, A <-- This file, named "imap_tools" is importing itself. That is a circular reference ImportError: cannot import name 'MailBox' from partially initialized module 'imap_tools' (most
Reply
#14
How about you try to solve this error yourself.

This is the error that caused your program to crash
Error:
TypeError: uid "<imap_tools.message.MailMessage object at 0x000002BFFD37BD60>" is not string
The error happened here:
Error:
File "C:\Users\Desktop\AppData\Local\Programs\Python\Python310\lib\site-packages\imap_tools\utils.py", line 30, in clean_uids raise TypeError('uid "{}" is not string'.format(str(uid)))
Notice that the path includes "Python310\lib\site-packages", this is a module that you installed in your Python.

It is very rare that there is an error in a module you installed, so it is likely the error was made when you called a function in the module. Search up the error trace until you see the name of a file you wrote. That would be here:
Error:
File "C:\Users\Desktop\Desktop\Python Spam Buster\DeleteEmailFiles.py", line 6, in <module> mailbox.delete(mailbox.fetch(A(body='a@*.*')))
Somewhere in this line you are passing an argument to a function that is supposed to be a string, but is instead a mailbox object. I would split the line in half to find out which call failed.
x = mailbox.fetch(A(body='a@*.*'))
print(x, type(x))
mailbox.delete(x)
When you run this you'll find out out if the problem is with fetch() or delete().
Reply
#15
Quote:Somewhere in this line you are passing an argument to a function that is supposed to be a string, but is instead a mailbox object. I would split the line in half to find out which call failed.
x = mailbox.fetch(A(body='a@*.*'))
print(x, type(x))
mailbox.delete(x)
When you run this you'll find out out if the problem is with fetch() or delete().

So the issue is with fetch()?

Is it a syntax issue with 'a@*.*' ?

Output below:
Error:
λ python DeleteEmailFiles.py File "C:\Users\Desktop\Desktop\Python Spam Buster\DeleteEmailFiles.py", line 8 x = mailbox.fetch(A(body='a@*.*')) ^ IndentationError: expected an indented block after 'with' statement on line 4
Reply
#16
No, look at the error message.
Error:
IndentationError: expected an indented block after 'with' statement on line 4
When you modified the code you did not maintain the indentation. I'm guessing your code looked something like this:
with MailBox('imap.mail.com').login(something) as mailbox:
    mailbox.delete(mailbox.fetch(A(body='a@*.*')))
But when you modified the code you made it look like this:
with MailBox('imap.mail.com').login(something) as mailbox:
x = mailbox.fetch(A(body='a@*.*'))
print(x, type(x))
mailbox.delete(x)
Indentation is how you define code blocks in Python. It serves the same purpose as curly brackets {} in C and C++. The "with" statement expects to be followed by an indented block of code. When you removed the indent, Python says it cannot parse the code.

To fix that problem you need to indent the code that follows the with statement.
with MailBox('imap.mail.com').login(something) as mailbox:
    x = mailbox.fetch(A(body='a@*.*'))
    print(x, type(x))
    mailbox.delete(x)
Reply
#17
Hello @deanhystad

I actually did try to indent, but received a syntax error. So, I'm getting errors no matter what I do, and that's confusing me.

from imap_tools import MailBox, A

with MailBox('imap.mail.yahoo.com').login('[email protected]', 'PWD', 'Bulk') as mailbox:
#    DELETE messages that contains 'a@*.*' in body from Bulk folder
#    mailbox.delete(mailbox.fetch(A(body='a@*.*')))

    x = mailbox.fetch(A(body='a@*.*'))
    print(x, type(x))
    mailbox.delete(x)python 
Invalid syntax error with indent:

Error:
λ python DeleteEmailFiles.py File "C:\Users\Desktop\Desktop\Python Spam Buster\DeleteEmailFiles.py", line 10 mailbox.delete(x)python ^^^^^^ SyntaxError: invalid syntax
Reply
#18
Don't you find it a little strange that there is "python" at the end of:
mailbox.delete(x)python
I'm not sure where you picked that up, but it is likely an incomplete python tag placed there by the forum editor. Try it without the "python"
with MailBox('imap.mail.yahoo.com').login('[email protected]', 'PWD', 'Bulk') as mailbox:
#    DELETE messages that contains 'a@*.*' in body from Bulk folder
#    mailbox.delete(mailbox.fetch(A(body='a@*.*')))
 
    x = mailbox.fetch(A(body='a@*.*'))
    print(x, type(x))
    mailbox.delete(x)
Reply
#19
Thank you for being patient and continuing to help... Smile


from imap_tools import MailBox, A

with MailBox('imap.mail.yahoo.com').login('[email protected]', 'PWD', 'Bulk') as mailbox:
#    DELETE messages that contains 'a@*.*' in body from Bulk folder
#    mailbox.delete(mailbox.fetch(A(body='a@*.*')))

    x = mailbox.fetch(A(body='a@*.*'))
    print(x, type(x))
    mailbox.delete(x)
Output error:
Error:
λ python DeleteEmailFiles.py <generator object BaseMailBox.fetch at 0x000002A0E617CC10> <class 'generator'> Traceback (most recent call last): File "C:\Users\Desktop\Desktop\Python Spam Buster\DeleteEmailFiles.py", line 10, in <module> mailbox.delete(x) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python310\lib\site-packages\imap_tools\mailbox.py", line 176, in delete uid_str = clean_uids(uid_list) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python310\lib\site-packages\imap_tools\utils.py", line 30, in clean_uids raise TypeError('uid "{}" is not string'.format(str(uid))) TypeError: uid "<imap_tools.message.MailMessage object at 0x000002A0E617BE20>" is not string
Reply
#20
from imap_tools import MailBox, A

with MailBox('imap.mail.yahoo.com').login('[email protected]', 'PWD', 'Bulk') as mailbox:
#    DELETE messages that contains 'a@*.*' in body from Bulk folder
    mailbox.delete(mailbox.fetch(A(body='a@*.*')))
Error output:
Error:
λ python DeleteEmailFiles.py Traceback (most recent call last): File "C:\Users\Desktop\Desktop\Python Spam Buster\DeleteEmailFiles.py", line 6, in <module> mailbox.delete(mailbox.fetch(A(body='a@*.*'))) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python310\lib\site-packages\imap_tools\mailbox.py", line 176, in delete uid_str = clean_uids(uid_list) File "C:\Users\Desktop\AppData\Local\Programs\Python\Python310\lib\site-packages\imap_tools\utils.py", line 30, in clean_uids raise TypeError('uid "{}" is not string'.format(str(uid))) TypeError: uid "<imap_tools.message.MailMessage object at 0x000001A96BC7BD90>" is not string
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Why does [root.destroy, exit()]) fail after pyinstaller? Rpi Edward_ 4 636 Oct-18-2023, 11:09 PM
Last Post: Edward_
  Python help for yahoo finance! Zshanar 7 3,375 Jul-31-2022, 05:27 PM
Last Post: paulyan
  Real time pricing Yahoo finance nathanz 1 2,522 Aug-09-2018, 01:02 PM
Last Post: metulburr
  An email with inline jpg cannot be read by all email clients fpiraneo 4 3,994 Feb-25-2018, 07:17 PM
Last Post: fpiraneo
  Email - Send email using Windows Live Mail cyberzen 2 5,932 Apr-13-2017, 03:14 AM
Last Post: cyberzen
  how to destroy or remove object rendered with opengl from the screen? hsunteik 1 7,068 Apr-09-2017, 01:30 PM
Last Post: hsunteik

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020