domainaware / parsedmarc

A Python package and CLI for parsing aggregate and forensic DMARC reports
https://domainaware.github.io/parsedmarc/
Apache License 2.0
966 stars 210 forks source link

Switching from IMAP to MSGraph "RuntimeError: folder INBOX not found" #365

Closed akkerkid closed 1 year ago

akkerkid commented 1 year ago

Until this week, ParseDMARC has been working great for me via IMAP. Now we're forced to switch to Graph API.

I think I got everything else figured out with Graph API permissions and IDs.
But here is where I'm stuck. You can clearly see that it's able to log in and detect the existing subfolders (like Aggregate and Forensic) under the Archive folder in the mailbox. But it can't find the INBOX folder.

Just for giggles, I renamed the Forensic folder and when I ran ParseDMARC, it was able to create a fresh Forensic folder. So I know it has good credentials and read and write permissions.

root@VM-parsedmarc:/# parsedmarc -c /etc/parsedmarc.ini --verbose --debug INFO:cli.py:777:Starting parsedmarc /usr/local/lib/python3.8/dist-packages/elasticsearch/connection/base.py:190: ElasticsearchDeprecationWarning: Elasticsearch built-in security features are not enabled. Without authentication, your cluster could be accessible to anyone. See https://www.elastic.co/guide/en/elasticsearch/reference/7.17/security-minimal-setup.html to enable security. warnings.warn(message, category=ElasticsearchDeprecationWarning) 0it [00:00, ?it/s] DEBUG:graph.py:126:Folder Archive already exists, skipping creation DEBUG:graph.py:126:Folder Aggregate already exists, skipping creation DEBUG:graph.py:129:Created folder Forensic DEBUG:graph.py:126:Folder Invalid already exists, skipping creation ERROR:cli.py:969:Mailbox Error Traceback (most recent call last): File "/usr/local/lib/python3.8/dist-packages/parsedmarc/cli.py", line 952, in _main reports = get_dmarc_reports_from_mailbox( File "/usr/local/lib/python3.8/dist-packages/parsedmarc/init.py", line 1085, in get_dmarc_reports_from_mailbox messages = connection.fetch_messages(reports_folder, batch_size=batch_size) File "/usr/local/lib/python3.8/dist-packages/parsedmarc/mail/graph.py", line 136, in fetch_messages folder_id = self._find_folder_id_from_folder_path(folder_name) File "/usr/local/lib/python3.8/dist-packages/parsedmarc/mail/graph.py", line 208, in _find_folder_id_from_folder_path return self._find_folder_id_with_parent(folder_name, None) File "/usr/local/lib/python3.8/dist-packages/parsedmarc/mail/graph.py", line 225, in _find_folder_id_with_parent raise RuntimeError(f"folder {folder_name} not found") RuntimeError: folder INBOX not found root@VM-parsedmarc:/#

akkerkid commented 1 year ago

Changing "INBOX" to "Inbox" in cli.py seems to have gotten it fixed. Something must be cap sensitive...

AnaelMobilia commented 1 year ago

Hello,

You can use the configuration file in order to define the "reports_folder" where parsedmarc will check for emails. This will ensure you that your issue will not come back when you will update parsedmarc ;-)

See https://domainaware.github.io/parsedmarc/#configuration-file

As you have found a solution on your issue (appears to be related to your mail server), I suggest you to close it.

Bests regards, Anael

fluidum commented 1 year ago

You don't have to replace code in cli.py. You need to define in your parsedmarc.ini I share my msgraph configure as an example in version 8.3.2.

[general]
save_aggregate = True
save_forensic = True
offline = True
debug = True

[elasticsearch]
hosts = <placeholder>
ssl = True
cert_path = <placeholder>

monthly_indexes = True

[msgraph]
auth_method = ClientSecret
mailbox = <placeholder>
client_id = <placeholder>
client_secret = <placeholder>
tenant_id = <placeholder>

[mailbox]
reports_folder = Inbox
batch_size = 1000