jamesridgway / attachment-downloader

Simple tool for downloading email attachments for all emails in a given folder using an IMAP client
MIT License
85 stars 39 forks source link

[help wanted] what is the correct regexp for subject filter ? #43

Closed changchichung closed 1 year ago

changchichung commented 1 year ago

I want to download attachments from emails with the keyword "invoice" in the subject , no matter where it was. I tried the following command, " but it didn't work. The displayed message on the screen does not match.

attachment-downloader --host imap.gmail.com --username aaa@aaa.com --password password --date-after 
"2023-07-07T00:00:00" --date-before="2023-07-31T23:59:00" --output /tmp --imap-folder Inbox --subject-regex "invoice"

2023-07-07 09:34:44,202 - INFO - Listing messages matching the following criteria: folder=Inbox, date__gt=2023-07-07, date__lt=2023-07-31
2023-07-07 09:34:44,500 - INFO - Fetch list of messages from folder 'Inbox'
2023-07-07 09:34:45,197 - INFO - Downloaded and parsed mail 'RMA invoice quotation' with 1 attachments
2023-07-07 09:34:45,198 - WARNING - Skipping message 'b'12632'' subject 'RMA invoice quotation' because it does not match invoice

but if I replace the regexp to RMA , then it works

attachment-downloader --host imap.gmail.com --username aaa@aaa.com --password password --date-after "2023-07-07T00:00:00" --date-before="2023-07-31T23:59:00" --output /tmp --imap-folder Inbox --subject-regex "RMA"
2023-07-07 09:34:09,012 - INFO - Listing messages matching the following criteria: folder=Inbox, date__gt=2023-07-07, date__lt=2023-07-31
2023-07-07 09:34:09,302 - INFO - Fetch list of messages from folder 'Inbox'
2023-07-07 09:34:09,983 - INFO - Downloaded and parsed mail 'RMA invoice quotation' with 1 attachments
2023-07-07 09:34:09,984 - INFO - Processing message 'b'12632'' subject 'RMA invoice quotation'
2023-07-07 09:34:09,984 - INFO - Downloading attachment '2023-07-06_10-33_d1kW1HER.png' to path /tmp/2023-07-06_10-33_d1kW1HER.png

any suggestions ?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

JohnnyGrey86 commented 12 months ago

This Python script uses re.match for the regular expression matching. From the manpage:

re.match() checks for a match only at the beginning of the string re.search() checks for a match anywhere in the string (this is what Perl does by default) re.fullmatch() checks for entire string to be a match