Download tier2_thunderbird/_attach/check_attachments.py from tanmaydeo/AutonexAI: direct link, hf CLI and curl.
- Browser
- Download file 2.54 kB
-
https://huggingface.co/datasets/tanmaydeo/AutonexAI/resolve/main/tier2_thunderbird/_attach/check_attachments.py
- Command line
-
hf download hf://datasets/tanmaydeo/AutonexAI/tier2_thunderbird/_attach/check_attachments.py
-
curl -L -o check_attachments.py https://huggingface.co/datasets/tanmaydeo/AutonexAI/resolve/main/tier2_thunderbird/_attach/check_attachments.py
2.54 kB
| #!/usr/bin/env python3 | |
| """Report whether a saved Thunderbird draft (matched by subject) carries a named | |
| attachment. Usage: check_attachments.py <subject-substring> <attachment-filename>. | |
| Prints "Attachment added!" if found, else "Attachment not found!". | |
| Robust: scans EVERY mbox file under the profile's Mail/ and ImapMail/ trees | |
| (not just a "Drafts" folder, since the draft may land in Local Folders/Drafts or | |
| the account Drafts depending on the identity's draft_folder). Also matches the | |
| attachment by a raw filename scan of the message body as a fallback (Thunderbird | |
| writes `filename="q3-report.pdf"` and/or `name="q3-report.pdf"` in the MIME part). | |
| Emits diagnostics so a run can be debugged from the captured stdout.""" | |
| import sys, os, glob, mailbox | |
| def mboxes(home): | |
| roots = glob.glob(os.path.join(home, ".thunderbird", "*", "Mail")) + \ | |
| glob.glob(os.path.join(home, ".thunderbird", "*", "ImapMail")) | |
| out = [] | |
| for r in roots: | |
| for dp, _dirs, files in os.walk(r): | |
| for f in files: | |
| if f.endswith(".msf") or f.endswith(".dat"): | |
| continue | |
| out.append(os.path.join(dp, f)) | |
| return out | |
| def main(): | |
| if len(sys.argv) < 3: | |
| print("Attachment not found!"); return | |
| subject, fname = sys.argv[1], sys.argv[2] | |
| home = os.path.expanduser("~") | |
| files = mboxes(home) | |
| print("DIAG scanned {} mbox files".format(len(files))) | |
| for path in files: | |
| try: | |
| raw = open(path, "r", encoding="utf-8", errors="replace").read() | |
| except Exception: | |
| continue | |
| if subject.lower() not in raw.lower(): | |
| continue | |
| print("DIAG subject found in", os.path.basename(path)) | |
| # structured check | |
| try: | |
| for msg in mailbox.mbox(path): | |
| if subject.lower() not in (msg.get("Subject", "") or "").lower(): | |
| continue | |
| for part in msg.walk(): | |
| disp = str(part.get("Content-Disposition") or "") | |
| pf = part.get_filename() or "" | |
| if "attachment" in disp.lower() and fname.lower() in pf.lower(): | |
| print("Attachment added!"); return | |
| except Exception: | |
| pass | |
| # raw fallback: the MIME part header names the file | |
| if ('filename="%s"' % fname).lower() in raw.lower() or \ | |
| ('name="%s"' % fname).lower() in raw.lower(): | |
| print("Attachment added!"); return | |
| print("Attachment not found!") | |
| main() | |