Replace A File From Email Attachment

I am looking for a method that would allow me to replace an existing file with one from an email attachment. Any way of scripting this, so when an email comes in from a particular email id, it takes the attached file, and replaces an existing file.

I did this with shell scripting and a handful of tools, like mail, sed and a base 64 decoder I wrote. The script would receive all mail, and if a message qualified, extract the Word or Excel files, turn them to plain text and extract the info for insertion into an rdbms table. Since I was dealing with a small number of senders using an even smaller number of mail clients, this sufficed. If you look at a mail message using a text editor, you can see the attachment in there.

------=_NextPart_01CE1C17.9F57CCC0
Content-Location: file:///C:/0CB82234/hwattachment_files/image001.gif
Content-Transfer-Encoding: base64
Content-Type: image/gif
R0lGODlhvgAiANUAAEBigPiYHRWV08/X39/l6p+wvxA6Ye/y9CBHa2B8ljBVdlBvi4+jta+9ynCJ
oFCw3m295EGp2/mlOcTk9PvFgPD4/PqyVv7s1IrK6TKi2SSc1v3lxl624fzSnOLy+ViWurbe8ZjQ
7PmrSP/58fu/cvieK7yXZG98hNuyeb2qjtPr9+qrWafX7rS4nfzYqq2ehP7y40FoiEV8oGecvVBo
fZ6Xh5jE0OyyYeu/hF2w2Ym3vr/K1X+WqgAtVv///wAAACH5BAAAAAAALAAAAAC+ACIAAAb/QJ9w
SCwaj8ikcslsOp/QqHQKvVBKgSyOd6B6v+CweBy1SrLobI1Hbrvf8Lc5TQ+YAPG8fs8Xzut1L3h9
hIWGTjAdZ4CAJQsJQzs8k5SVlpc8O5KYnJMEm5VHA5cFh6ZPLiJpFox0KD1sQjw9tLW2t7iws7m8
tJK4RgcGuA2nxkokFi06EA/OziwjGx2saRI0PTtDu73dut65v7dGC7iQx+hGNxEC7e7tHkQbqlkp
tF2y4N2T+rfitkUY4EKAL51BHzbevYtgZASJACsQ9EBAhFu/W/wu+rJIiwiBYbcGHByJQaE7CEgs
nKC1oKJGXBltAZhJs+bMUcCGKIA5cuQE/5PtMCBpUCuWkh24tB3h2KMJ0224BvU8CAEoB1EgszFB
6g/JUyZfudoyQGBqz6oKMxgZkLVHwSRiayk18nXJ0wMSbxUzBkC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iHJRKNbQzjA55GzMc9gtlCGw2QCE0k
+KjTjGpk0pkJz+ZCJvOcx3UoQoAGe9CX3HksgLEogARnIsFpvSFnqtLUJ1RFQxoeYIapSgIOUVWc
AQxtYdMiigttNQkG4GsTxSEiEMfkQh9Ujlxe8uEkCtBE1oxkdVbMohYRc7ItejGLifuiE4IAADs=
------=_NextPart_01CE1C17.9F57CCC0
Content-Location: file:///C:/0CB82234/hwattachment_files/filelist.xml
Content-Transfer-Encoding: quoted-printable
Content-Type: text/xml; charset="utf-8"
<xml xmlns:o=3D"urn:schemas-microsoft-com:office:office">
<o:MainFile HRef=3D"../hwattachment.htm"/>
<o:File HRef=3D"themedata.thmx"/>
<o:File HRef=3D"colorschememapping.xml"/>
<o:File HRef=3D"image001.gif"/>
<o:File HRef=3D"filelist.xml"/>
</xml>
------=_NextPart_01CE1C17.9F57CCC0--

An example of some of the scripting would be appreciated.

If your file is very much just text, you can include it verbatim like the latter attachment filelist.xml, but if it is binary, you need an base 64 encoder (simple in C, PERL, JAVA, etc., probably available online for free) to encode your file. Older email used uuencode for the same sort of function, but with appropriate tags.

Requirements first: Do you just want to receive an email, send an email, or forward one with a new or replaced attachment? Replacement seems a bit deceptive....

Bumping up posts or double posting is not permitted in these forums.

Please read the rules, which you agreed to when you registered, if you have not already done so.

You may receive an infraction for this. If so, don't worry, just try to follow the rules more carefully. The infraction will expire in the near future

Thank You.

The UNIX and Linux Forums.