(OLDER) <- More Stuff -> (NEWER) (NEWEST)
Printer Friendly Version



More using the spooler to print to email: email attachments

By Dirk Hart
Adanac Software
Email: dhart@mailstarusa.com
Web Site: http://www.mailstarusa.com



We already know how to modify a spooler interface script to email plain text to people, but it bothered me that print jobs with embedded PCL commands or other escape codes might get mangled in the emailing process.

Normally when we want to email stuff with non-text characters in it we have to uuencode it on one end and uudecode it on the other end just so we can be sure the whole thing gets transmitted properly. This is no guarantee that the file won't look like trash, it just makes sure the whole file arrives unmangled. What uuencode does is convert all the characters in a file to ascii (ascii *pairs* of characters actually) and uudecode is our friend when we want to undo that process.

The unix mail command isn't smart enough to uuencode stuff. You could write a script that places attachment boundaries (markers) around your uuencoded file and then email the entire mess away, but thats too much like work. Fortunately we have another mail program called mutt that does the job for us.

I found mutt at ftp://ftp2.sco.com/pub/skunkware/osr5/vols/ in a file called mutt-1.2.5.1-VOLS.tar which I installed on my ancient OpenServer 5.0.4 system with custom. This part was easy but I soon ran into trouble when i tried to execute mutt. I got an error that said dynamic linker : mutt : error opening /usr/local/lib/libncurses.so.4 . This was not the same result as having my email attachments bombard the internet, so I cast about for a solution. I searched high and low for libncurses, ncurses and curses to no avail, until someone pointed out that the ncurses package was on the skunkware ftp site (thanks, JPR). Off I flew with my browser to ftp://ftp2.sco.com/pub/skunkware/osr5/vols/ and just a few lines below the mutt package was the ncurses package i needed, which I downloaded and installed with custom.

This time when I tried mutt I got a 'character-graphical' screen with a mini-menu and such that made it easy to send a test message. So I did.

Since that seemed to work just fine i typed in mutt -help and discovered how to attach a file to an email. From the command line point of view seems to be a lot like the familiar mail command. I typed in echo test|mutt -a /etc/hosts -s test boopy and sure enough boopy received an email with the contents of /etc/hosts. Pretty painless, actually.

Next, I set about modifying the spooler interface script for my all-too-cleverly named print-to-email spooler destination, called email. Previously we had modified the FILTER or modified the script like this:


{
while [ $i -le $copies ]
do
       for file in $files
       do
               0<${file} eval ${FILTER} 2>&1
               echo "\014\c"
       done
       i=`expr $i + 1`
done
} | mail -s report boopy
 

But it wasn't clear to me if this would email *all* files in $files or the first or the last (not that I tested this, though), so I changed the script to the less ambiguous

while [ $i -le $copies ]
do
       for file in $files
       do
{
               0<${file} eval ${FILTER} 2>&1
               echo "\014\c"
} | /usr/local/bin/mutt -a $file -s test boopy
       done
       i=`expr $i + 1`
done
 

incorporating the appropriate changes for mutt. This change will send each $file in $files as a separate email to boopy. When boopy joyously receives our email our attachment will show up, and if (in mozilla) we have check View-->Display Attachments Inline the uuencoded (and decoded) document is displayed including all the non-ascii characters we might have sent. But at least we have the option of printing the attachment along with all its PCL codes.




More Articles by Dirk Hart




Click here to add your comments



Don't miss responses! Subscribe to Comments by RSS or by Email

Click here to add your comments


If you want a picture to show with your comment, go get a Gravatar



/DirkHart/dhemailmutt.html copyright December 2003 Dirk Hart All Rights Reserved

Have you tried Searching this site?

Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates

This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.

Publishing your articles here

Jump to Comments



Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.

Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.

We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.


book graphic unix and linux troubleshooting guide

My Troubleshooting E-Book will show you how to solve tough problems on Linux and Unix systems!



 I sell and support
 Kerio Mail server






More:
       - Mail
       - Printing
       - DirkHart


Unix/Linux Consultants

Skills Tests

Guest Post Here