* On 28 Jul 2013, [email protected] wrote:
> > Today as I was saving about 20 photos I received from my sister,
> > I thought I wonder if there is a way to save all of the images
> > attached to an email in one swoop as opposed to hitting s for each
> > one. How do you guys manage attachments?
>
> I wrote this small script; invoke it by "|muttrip dir". It depends
> on having ripmime installed. The followup .pl program merely builds
> a crude index.html file and reports how many files it found; you can
> skip it.
Adding to this theme: I receive voice mail as wav attachments, but I
don't "view" them through mutt. I have a procmail rule that sends
voicemail messages to a python script (attached). This script saves all
audio/* attachments to a designated location with a unique filename. It
could easily be adapted as an ad hoc bulk attachment filer.
--
David Champion • [email protected]
#!/usr/bin/env python
import os
import sys
import email
import email.parser
import errno
def extract(m):
n = 0
audio = []
for part in m.walk():
n += 1
if part.get_content_type().startswith('audio/'):
data = part.get_payload(decode=True)
params = dict(part.get_params())
if 'name' in params:
name = params['name']
else:
name = 'attachment%03d.wav' % n
fp = open(name, 'w')
fp.write(data)
fp.close()
audio.append(name)
return audio
def main(args):
os.chdir(os.path.dirname(sys.argv[0]))
p = email.parser.Parser()
m = p.parse(sys.stdin)
audio = extract(m)
for file in audio:
base, ext = os.path.splitext(file)
if '_' in base:
caller, date, timeofday = base.split('_')
dir = date[:6]
else:
dir = time.strftime('%Y%m')
try:
os.makedirs(dir)
except OSError, e:
if e.errno == errno.EEXIST:
pass
os.rename(file, os.path.join(dir, file))
if len(audio):
return 0
return 1
if __name__ == '__main__':
sys.exit(main(sys.argv[1:]))