reddragdiva: (Default)
[personal profile] reddragdiva

This could be, line for line, the most horrible shell script I have ever perpetrated. At least it admits it.

#!/usr/bin/ksh

# XXX_XXXX_receive
# Receives mail to user mail_in, saves attachments, deletes mail
#
# D. Gerard    17-Jan-2006     First version
#                              This version is horribly inefficient,
#                              but it works and it's very clear what it does.
#                              A more efficient version would process the
#                              mailbox file itself to extract the message.

# This script requires the installation of munpack to decode the attachments
# - see http://www.uwsg.iu.edu/usail/mail/mime/munpack.html
#       http://asg.web.cmu.edu/andrew2/staff/jgm/
#       http://www.sunfreeware.com/programlistsparc8.html#mpack


# this is where our incoming files end up
SAVEDIR=/tmp/XXXX_receive

# is there any mail at all?
if mailx -e -u mail_in
        then

# We have mail.

# Loop through mailbox one message at a time

        while mailx -e -u mail_in
        do

# We go into mailx, print a message and delete it
# note that /home/mail_in/.mailrc contains:
#    set quiet
#    unset header
#    set prompt=""
# Then we extract attachment if any (not text)

        (echo P; echo d; echo q) | mailx -Bn -u mail_in | munpack -C $SAVEDIR

        done

rm /tmp/$$
rm -f $SAVEDIR/*.desc

fi

My geeky readers are about to tell me how I should have done it. But that doesn't account for the law of conservation of programmer mental effort. Besides, this is proprietary software; I have standards to work to.

(no subject)

Date: 2006-01-17 05:56 pm (UTC)
From: [identity profile] lpetersson.livejournal.com
At least you REMs are cute :)

(no subject)

Date: 2006-01-17 06:02 pm (UTC)
From: [identity profile] axy-666.livejournal.com
Waaaaaaaaay over my head.. but I think the icon says it all..

(no subject)

Date: 2006-01-17 06:06 pm (UTC)
From: [identity profile] arkady.livejournal.com
I think I can follow it, but only because a) it's commented to fuck, and b) I've been dipping in and out of the O'Reilly BASH book since getting fired from Syzygy (oh look, I haven't given it back yet, how remiss of me...).

(no subject)

Date: 2006-01-17 06:11 pm (UTC)
From: [identity profile] arkady.livejournal.com
Yup, I spotted that. Well done, dear heart - you're well en route to becoming the Damian Hurst of shell scripting!

(no subject)

Date: 2006-01-17 06:17 pm (UTC)
From: [identity profile] axy-666.livejournal.com
My coding is crap at the best of times, I'm just getting my head around linux so it'd be a while until I manage it..

(no subject)

Date: 2006-01-17 06:23 pm (UTC)
From: [identity profile] sweh.livejournal.com
ksh is more able than bash for coding stuff. bash may have a better command line interface (but I prefer ksh for that as well) but ksh is superior for programming.

(no subject)

Date: 2006-01-17 06:28 pm (UTC)
From: [identity profile] axy-666.livejournal.com
Still over my head tbh.. most of my php is taken and modified from scripts..

(no subject)

Date: 2006-01-17 06:29 pm (UTC)
From: [identity profile] sweh.livejournal.com
Using "formail" (from the procmail package) would save loading mailx each time. Since you've already got third party software (munpack) installed... :-)

(no subject)

Date: 2006-01-17 06:31 pm (UTC)
From: [identity profile] sweh.livejournal.com
My longest ksh program (written in 1992) was about 1200 lines long. And the core of it is still in use (although I left that company 10 years ago).

(no subject)

Date: 2006-01-17 06:38 pm (UTC)
From: [identity profile] axy-666.livejournal.com
aye I've started to do that with my php sites.. most of the static content is in one file with the file being called on each page and then it's a matter of just echoing the strings..

(no subject)

Date: 2006-01-17 07:43 pm (UTC)
From: [identity profile] poggs.livejournal.com
You get paid by the hour.

(no subject)

Date: 2006-01-17 08:09 pm (UTC)
From: [identity profile] shamus9999.livejournal.com
You remind me of a painful memory: an "Enterprise Back Up and Disaster Recovery Solution" (they probably call it an eParadigm nowadays). Thankfully I can't remember the name of this fine product, designed to run in Winblows NT on a DEC Alpha server.

The DEC box could do graphics using ony one of two makes and models of video card and was limited to, I believe, 640x480 resolution. This fine program lacked the standard resizable windows and needed at least 800x600 in order not to truncate the display (which included the names and time/date stamps of the files available to restore). Their engineers just couldn't understand that a server just might not have a large monitor at its console and a gamer's video card (this was the mid-1990s). They'd have been happy to add resizable windows as a customization if we'd pay them to. Bastards.

(no subject)

Date: 2006-01-17 11:50 pm (UTC)
vatine: Generated with some CL code and a hand-designed blackletter font (Default)
From: [personal profile] vatine
Bah, the "obvious" way of... hey, Solaris you said? Probably won't work, if Sun's kept up their somewhat (better but still) peculiar mbox format:

awk 'BEGIN { cnt=0; } /^From / { cnt++; } {print >> cnt; ]' < $MAIL

Lands you with files numbered from 1 upwards, in the current directory, one mail per file, using Standard Mbox File Format (line starting "From " is the first line of a new mail, that's why "From" first on a line gets mangled to ">From").

On the other hand, that'd probably be considered "abstruse awk" and that type of thing can land you in the awk-ward.

Totally off topic!

Date: 2006-01-18 12:25 am (UTC)
From: [identity profile] misshavisham.livejournal.com
I have just been tooling around on the big wide world known as the internet and have seen that there is an upcoming exhibition:

http://tate.org.uk/britain/exhibitions/gothicnightmares/default.shtm

With my aromatherapy business, each line is associated with a particular famous painting. The first cab off the rank was a "Nightmare Mist" and this is the painting for that range (my print of it is being framed as we speak) :)

I was wondering if you could please keep an eye out for any free literature or brochures about the exhibition and post them to me? I'd be eternally grateful!

Re: Totally off topic!

Date: 2006-01-18 12:31 am (UTC)
From: [identity profile] misshavisham.livejournal.com
Thanks so much! I'm really hoping it comes here as well but that could easily be a year away :|

Postal address is

Miss Havisham
PO Box 615
Marrickville
NSW 1475

(no subject)

Date: 2006-01-18 04:56 am (UTC)
From: [identity profile] grumpy-sysadmin.livejournal.com
I could spew things about procmail, formail, and Perl but, hey, whatever.

I figure you spent about as long making sure the commands to mailx did the right thing across the board as you could have spent reading docs.