Best way to archive attachments

email

My saved-messages and sent-mail "folders" (actually Unix MBX files)
are huge because of attachments, most of which I've saved to disk
anyway.

I want to keep the messages, but replace the attachment w/ a text file
saying "Attachment removed: /full/path/to/attach.txt".

How do I do this?

I'm using Alpine, but any tool that does this for Unix MBX is
fine. Alpine does let me delete attachments from emails, but I can't
replace them w/ a text file. Notes:

  • I realize I can save the message to a file and edit the file using
    emacs, but that's kludgey and probably messes up "Content-Length"
    headers and stuff.

  • I also realize I can forward the message, with headers, to myself
    after removing the attachment. Again, kludgey.

  • I don't think Alpine lets me add attachments to stored mail
    (unless I want to send it somewhere [which messes up headers]), so I
    can't delete the big attachment and add a smaller one.

  • I realize I could write a Perl script to do this, but hoping for
    an existing well-tested solution.

Best Answer

OK, I poked aorund, and when Alpine "deletes" an attachment, it actually replaces it with something like:

Content-Type: Text/Plain; charset=US-ASCII
X-Content-Type: image/jpeg
X-Content-Transfer-Encoding: base64
Content-ID: <part1.07020604.05000506@flamescape.com>

  [ The following attachment was DELETED when this message was saved:    ]
  [ A Image/JPEG segment of about 93,336 bytes.                          ]

I can then use emacs to edit this message (and it doesn't mess up any Content-Length headers or anything)

Related Question