[Users] Save all attachments from all emails
Philippe Gramoullé
philippe at gramoulle.com
Tue Apr 23 02:37:37 CEST 2013
Hello Holger,
On Sat, 20 Apr 2013 20:59:16 +0200
Holger Berndt <berndth at gmx.de> wrote:
| Hello Philippe,
|
| On Sa, 20.04.2013 00:37, Philippe Gramoullé wrote:
|
| >Well, since i have so many years worth of email, i'd like to extract all attachments
| >of all emails in a single folder so i can more easily browse through pictures, PDFs, videos, etc..
| >
| >Basically, i'd like to use the same feature as "Save all attachments" but for all emails inside a folder
| >
| >What would be the easiest way ? Perl/Python script using the Perl/Python plugins ?
|
| I think it would probably be easiest to do it from outside Claws Mail.
| Claws Mail's default storage format MH is quite easy to parse for
| other tools.
|
| I attached a script that I use as a filter to store pictures of some
| incomming mails automatically to a folder - but it should also be able
| to do what you want, e.g.
|
| store all attachments of a mail folder tree
|
| extract_attachments_from_mime_message.py --all-content-types --recursive /path/to/mail/folder /path/to/target/folder
|
| You can also select which attachments to store based on MIME type,
| e.g. only image/* and application/pdf:
|
| extract_attachments_from_mime_message.py --content-type image --content-type application/pdf --recursive /path/to/mail/folder /path/to/target/folder
|
| Maybe it helps. Beware that these are not very well tested (because I
| use the script differently) - no guarantees.
|
| You can also check out --help.
|
| Holger
Well, thank you so much, this is _exactly_ what i was looking for !
Right now, i'm more looking into "--all-content-types" as i want to extract (and backup) every possible attachment from my MH Folder.
I tried your script in few directories and it works 99.99% of the time, which means that i was able to find, for now, a few emails that would make the script exit with with an error:
./extract_attachments_from_mime_message.py --all-content-types ~/SylpheedMail/inbox/32831 /tmp/claws-mime3
Traceback (most recent call last):
File "./extract_attachments_from_mime_message.py", line 170, in <module>
sys.exit(main())
File "./extract_attachments_from_mime_message.py", line 166, in main
extract_attachments(args.mime_filename, args.target_directory[0], args.content_type, args.subfolder_by_sender, args.recursive)
File "./extract_attachments_from_mime_message.py", line 133, in extract_attachments
mime_file.extract(target_directory, patterns)
File "./extract_attachments_from_mime_message.py", line 102, in extract
fp.write(part.get_payload(decode=True))
TypeError: must be string or buffer, not None
If you're interested to reproduce and fix , i can provide you the offending emails offlist. These are mainly mails with dozens of attachments.
Thanks for your help :)
Truly yours,
Philippe
More information about the Users
mailing list