Sponsored Content
Operating Systems Linux Replace A File From Email Attachment Post 302777905 by DGPickett on Friday 8th of March 2013 04:16:15 PM
Old 03-08-2013
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.
Code:
------=_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/JUyZfudoyQGBqz6oKMxgZkLVHwSRiayk18nXJ0wMSbxUzBkCkWSI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KNbQzjA55GzMc9gtlCGw2QCE0k
+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--

 

10 More Discussions You Might Find Interesting

1. How do I send email?

Transfering unix file as an email attachment

I've written a a script which generates a report file, saved to a unix directory. I need to transfer it, via email, to some users. The command I'm using in my script is: (note that subject & cur_address are set in the script prior to this line) cat /u/sandyl/sm_o_commdt_archive/c | uuencode... (3 Replies)
Discussion started by: slivi
3 Replies

2. UNIX for Dummies Questions & Answers

Transfering unix file as an email attachment

I've written a a script which generates a report file, saved to a unix directory. I need to transfer it, via email, to some users. The command I'm using in my script is: (note that subject & cur_address are set in the script prior to this line) cat /u/sandyl/sm_o_commdt_archive/c | uuencode... (3 Replies)
Discussion started by: slivi
3 Replies

3. Shell Programming and Scripting

UNIX file attachment in email

Hi, I have a syntax for mail attachment as $EMAIL "Wrapper $wrapper_script_name has failed" " $wrapper_script_name has Failed " $failed_email_address and $EMAIL is as below MSGSub=${1} MSGText=${2} RMAIL=${3} #set LANG='' export LANG='' echo "${MSGSub}" | mailx -s "${MSGText}" ... (1 Reply)
Discussion started by: satgur
1 Replies

4. Shell Programming and Scripting

Sending email and attachment file using Perl

I am trying to send an email body of information and also attachment using perl script, but I am only able to send the body but not an attachment. is there around it without using "use MIME::Lite;" module. $user = "bataf\@xyz.com"; $subjectt = "mail from perl"; open(MAIL, "| mailx -s... (1 Reply)
Discussion started by: bataf
1 Replies

5. Shell Programming and Scripting

Send a file through email using cron as an attachment

Hi All, I want to send a file as an attachment through cron job.Is this possible using cronjob nd if it i, can you please let me know how to do this? Thanks (2 Replies)
Discussion started by: NARESH1302
2 Replies

6. UNIX for Advanced & Expert Users

email file as attachment...

Hello all, i am on hp-ux 11.23...i am trying to send an email as an attachement but it dose not seem to work...after reading on google i found that we can use uuencode to send file at attachement...here is my file and the syntax $ cat test.txt NAME --------- TEST $ uuencode... (7 Replies)
Discussion started by: abdul.irfan2
7 Replies

7. Shell Programming and Scripting

Sending a file as an attachment to email

The file is located under appl/batchdata/ file name: storesales.txt I am using following code because uuencode is not present. I am not getting the data in file but i am getting the blank file with same name as an email attachment. ( echo "from: sch@xxxx.com" echo "to:sch@xxxx.com" echo... (2 Replies)
Discussion started by: skatpally
2 Replies

8. Shell Programming and Scripting

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. (6 Replies)
Discussion started by: evencustard
6 Replies

9. Shell Programming and Scripting

Email with .dat file as attachment

Hi, I am trying to email a .dat file as an attachment from unix MS-outlook. I tried uuencode but it is not attaching the file, rather it is placing some junk data in the body of mail. Below is my code (cat Message.txt; uuencode Attach_File.DAT Attch_File.DAT) | mailx -s "SUBJECT"... (12 Replies)
Discussion started by: sampoorna
12 Replies

10. UNIX for Dummies Questions & Answers

Cronjob output to file AND to email (as attachment)

I have a shell script that runs on our webserver logs, and grabs various useful data and then outputs this data to a .csv file. What I want to do now is schedule a cronjob to run this script for me each week at a designated time, AND email the .csv file that is created as an attachment to... (1 Reply)
Discussion started by: xdawg
1 Replies
REFORMIME(1)						      Double Precision, Inc.						      REFORMIME(1)

NAME
reformime - MIME E-mail reformatting tool SYNOPSIS
reformime [options...] DESCRIPTION
reformime is a utility for reformatting MIME messages. Generally, reformime expects to see an RFC 2045[1] compliant message on standard input, except in few cases such as the -m option. If no options are given, reformime prints the MIME structure of the message. The output consists of so-called "MIME reference tags", one per line. For example: 1 1.1 1.2 This shows that the message contains two different MIME sections. The first line of the MIME structure output will always contain "1", which refers to the entire message. In this case it happens to be a multipart/mixed message. "1.1" refers to the first section of the multipart message, which happens to be a text/plain section. "1.2" refers to the second section of the message, which happens to be an application/octet-stream section. If the message is not a MIME message, or it does not contain any attachments, reformime prints only "1", that refers to the entire message itself: 1 Here's the output from reformime when the first part of the message was itself a multipart/alternative section: 1 1.1 1.1.1 1.1.2 1.2 Arbitrarily complex MIME constructs are possible. OPTIONS
-d Parse a delivery status notification MIME message (RFC 1894[2]). reformime expects to see on standard input a MIME message that consists of a delivery status notification, as defined by RFC 1894. reformime reads the message and prints on standard output a list of addresses and their corresponding delivery status, as specified in the delivery status notification. Each line printed by reformime consists of a delivery status, a space, and the address. reformime then terminates with a 0 exit status. reformime produces no output and terminates with an exit status of 1 if the standard input does not contain a delivery status notification. -D Like the -d except that reformime lists the address found in the Original-Recipient: header, if it exists. -e Extract the contents of the indicated MIME section, and display it on standard output. The -s option is required when -e is specified. If the specified section or sections use either the base64 or quoted-printable encoding method, reformime automatically decodes it. In this case you're better off redirecting the standard output into a file. -i Display MIME information for each section. reformime displays the contents of the Content-Type: header, any encoding used, and the character set. reformime also displays the byte offset in the message where each section starts and ends (and where the actual contents of the section start, after skipping all the headers). -m Create a multipart/digest MIME message digest. -r Rewrite message, adding or standardizing RFC 2045[1] MIME headers. -r7 Like -r but also convert 8bit-encoded MIME sections to quoted-printable. -r8 Like -r but also convert quoted-printable-encoded MIME sections to 8bit. -s section Display MIME information for this section only. section is a MIME specification tag. The -s option is required if -e is also specified, and is optional with -i. Multiple sections may be specified by separating them with commas. reformime processes each section using the other options that were specified. -x Extract the contents of the indicated MIME section to a file. -X Pipe the contents of the indicated MIME section to a program. Extracting RFC 2045 MIME section(s) to file(s) The -x and -X options extract a specific MIME section to a file or to a pipe to an external program. Use the -s option to identify the MIME section to extract. If the -s option is not specified, every MIME section in the message is extracted, one at a time. If -s lists multiple sections, each section gets extracted separately. quoted-printable and base64 encoding are automatically decoded. -x Interactive extraction. reformime prints the MIME content type of each section. Answer with 'y' or 'Y' to extract the MIME section. Specify the filename at the next prompt. reformime prompts with a default filename. reformime tries to choose the default filename based on the MIME headers, if possible. If not, the default filename will be attachment1.dat (if the -s option is not specified, the next filename will be attachment2.dat, and so on). -xPREFIX Automatic extraction. reformime automatically extracts one or more MIME sections, and saves them to a file. The filename is formed by taking PREFIX, and appending the default filename to it. Note that there's no space between "-x" and "PREFIX". For example: reformime -xfiles- This command saves MIME sections as files-attachment1.dat, then files-attachment2.dat, etc. reformime tries to append the filename specified in the MIME headers for each section, where possible. reformime replaces all suspect characters with the underscore character. -X prog arg1 arg2 ... The -X option must be the last option to reformime. reformime runs an external program prog, and pipes the contents of the MIME section to the program. reformime sets the environment variable CONTENT_TYPE to the MIME content type. The environment variable FILENAME gets set to the default filename of reformime's liking. If the -s option is not specified, the program runs once for every MIME section in the message. The external program, prog must terminate with a zero exit status in order for reformime to proceed to the next MIME section in the message (or the next section specified by -s). In any case, if prog terminates with a non-zero exit status, reformime terminates with the exit status of 20 plus prog's exit status. Note reformime extracts every MIME section in the message unless the -s option is specified. This includes even the text/plain MIME content that usually precedes a binary attachment. Adding RFC 2045 MIME headers The -r option performs the following actions: If there is no Mime-Version:, Content-Type:, or Content-Transfer-Encoding: header, reformime adds one. If the Content-Transfer-Encoding: header contains 8bit or raw, but only seven-bit data is found, reformime changes the Content-Transfer-Encoding header to 7bit. -r7 does the same thing, but also converts 8bit-encoded content that contains eight-bit characters to quoted-printable encoding. -r8 does the same thing, but also converts quoted-printable-encoded content to 8bit, except in some situations. Creating multipart/digest MIME digests The -m option creates a MIME digest. reformime reads a list of filenames on standard input. Each line read from standard input contains the name of a file that is presumed to contain an RFC 2822-formatted message. reformime splices all files into a multipart/digest MIME section, and writes it to standard output. Translating MIME headers The following options do not read a message from standard input. These options process MIME headers via the command line, and are designed to be conveniently used by mail-handling scripts. -h "header" Decode a MIME-encoded "header" and print the decoded 8-bit content on standard output. The decoding gets carried out as if the contents occurred in the "Subject" header. Example: $ reformime -h '=?iso-8859-1?Q?H=F3la!?=' Hola! -H "header" Like -h except that header is parsed as a list of email addresses, like "From" or "To". -o "text" MIME-encode "text", and print the results on standard output. -O "text" Like the -o option, except that text is a structured header with RFC 2822 addresses. -c "charset" Use charset as the character set setting, by the -h, -H, -o and -O options. -u This "undocumented" option reads a MIME message on standard input, and converts its contents to an UTF-8-encoded character stream, which is written to standard output. The standard output receives a concatenated amalgam of the headers and "text" MIME object data. It is meant to be used as part of a generic search function. This option decodes various kinds of header MIME encoding, the quoted-printable and base64 transfer encodings of "text" MIME objects. SEE ALSO
reformail(1)[3], sendmail(8), mailbot(1)[4], maildrop(1)[5], maildropfilter(5)[6], egrep(1), grep(1), sendmail(8). AUTHOR
Sam Varshavchik Author NOTES
1. RFC 2045 http://www.rfc-editor.org/rfc/rfc2045.txt 2. RFC 1894 http://www.rfc-editor.org/rfc/rfc1894.txt 3. reformail(1) [set $man.base.url.for.relative.links]/reformail.html 4. mailbot(1) [set $man.base.url.for.relative.links]/mailbot.html 5. maildrop(1) [set $man.base.url.for.relative.links]/maildrop.html 6. maildropfilter(5) [set $man.base.url.for.relative.links]/maildropfilter.html Courier Mail Server 08/30/2011 REFORMIME(1)
All times are GMT -4. The time now is 02:31 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy