Sponsored Content
Top Forums Shell Programming and Scripting scripting mail receipt and saving attachment Post 302570479 by Corona688 on Thursday 3rd of November 2011 11:51:05 AM
Old 11-03-2011
You shouldn't be trying to automate an interactive program like MUTT. You should be checking the contents of your ~/.maildir yourself, or wherever MUTT keeps its mail. Being descended from a local-mail program, MUTT ought to be keeping its emails in their ordinary plain-text format.

I'm a bit rusty with ~/.maildir things, but:

Code:
# Create new timestamp file
touch ~/.lastmail2

if [ -f  ~/.lastmail" ]
then
        # Find everything newer than the last timestamp file
        find ~/.maildir -type f -newer ~/.lastmail > /tmp/$$
else
        # Find all mail files
        find ~/.maildir -type f > /tmp/$$
fi

# Replace the old timestamp file with the new
mv ~/.lastmail2 ~/.lastmail

# Read the list of files line-by-line.
while read FILE
do
        echo "Processing mail file $FILE"
done < /tmp/$$

rm /tmp/$$

"Subject:" ought to be a line by itself. I'm less sure how to extract attachments, it probably involves base64 or uuencode. If you mailed a small harmless attachment to yourself, and attached the resulting file found in your .maildir, I could probably work something out.
 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

mail attachment

This question has been asked many time before. I did search other questions. But was not able to work out. Really sorry for repeating the same question. I have mail and mailx and sendmail installed. It Tried this uuencode FILENAME.txt FILENAME.txt | mail mymail@yahoo.com the attachment... (3 Replies)
Discussion started by: sushrut
3 Replies

2. UNIX for Advanced & Expert Users

Saving of UNIX based e-mail on to local disks

Dear friends, Someone please let me know how to store e-mail on local hard disk or floppy disks. I am using UNIX based PINE e-mail programme and the copy of this mail I wanted to store it in my local disks. Thanks in advance. Regards, Rajan (4 Replies)
Discussion started by: rajan9
4 Replies

3. UNIX for Advanced & Expert Users

mail receipt

how can I control a mail receipt sent from unix using sendmail (4 Replies)
Discussion started by: npires
4 Replies

4. Shell Programming and Scripting

mail with attachment

Hi, I am facing an issue while sending a mail from unix with attachment.the issue is i am able to send a mail with attachment but...after receiving the mail if u see that the text is continous though it was line by line in original.. UUENCODE is the cmd i am using... plz help me in this... (1 Reply)
Discussion started by: param786
1 Replies

5. UNIX for Advanced & Expert Users

mailx commannd - Mail and Attachment in same mail

Hi , I am using mailx command for sending the mails. Rightnow I am sending the attachment (by using uuencode $filename) as a seperate mail.I wanna send the attachment also with the same mail. (6 Replies)
Discussion started by: sharif
6 Replies

6. Shell Programming and Scripting

Mail attachment with unix mail

Hi Could someone help me with the details on how to send an attachment through mail in unix. I have an html file in my unix machine and I want this to be send to some mail id, plese help with the steps. Regards Ajay (2 Replies)
Discussion started by: ajaykumarboyana
2 Replies

7. UNIX for Dummies Questions & Answers

How to send html file in a mail not as an attachment but it should display in the mail in table for

Hi The below script working when we are sending the html as attachment can u please guide how to send thesmae data in table form direct in the mail and not in mail attachment . cat Employee.sql SET VERIFY OFF SET PAGESIZE 200 SET MARKUP HTML ON SPOOL ON PREFORMAT OFF ENTMAP ON - HEAD... (0 Replies)
Discussion started by: mani_isha
0 Replies

8. Shell Programming and Scripting

Mail Attachment...

Hi All, I am new to unix. I have written the script to identify the delimiter count for my source file and the output I have to capture in another file and that file should sent to mail with attachment. I have tried to send the attachment with below script . But I am not able to do that. Any... (2 Replies)
Discussion started by: suresh_target
2 Replies

9. Shell Programming and Scripting

Mail attachment

Hi, I want to send an attachment and content in a single mail using unix command can anyone pls help me? Thanks Naveen A (6 Replies)
Discussion started by: Pranaveen
6 Replies
maildir(5)                                                      File Formats Manual                                                     maildir(5)

NAME
maildir - directory for incoming mail messages INTRODUCTION
maildir is a structure for directories of incoming mail messages. It solves the reliability problems that plague mbox files and mh fold- ers. RELIABILITY ISSUES
A machine may crash while it is delivering a message. For both mbox files and mh folders this means that the message will be silently truncated. Even worse: for mbox format, if the message is truncated in the middle of a line, it will be silently joined to the next mes- sage. The mail transport agent will try again later to deliver the message, but it is unacceptable that a corrupted message should show up at all. In maildir, every message is guaranteed complete upon delivery. A machine may have two programs simultaneously delivering mail to the same user. The mbox and mh formats require the programs to update a single central file. If the programs do not use some locking mechanism, the central file will be corrupted. There are several mbox and mh locking mechanisms, none of which work portably and reliably. In contrast, in maildir, no locks are ever necessary. Different delivery processes never touch the same file. A user may try to delete messages from his mailbox at the same moment that the machine delivers a new message. For mbox and mh formats, the user's mail-reading program must know what locking mechanism the mail-delivery programs use. In contrast, in maildir, any delivered message can be safely updated or deleted by a mail-reading program. Many sites use Sun's Network Failure System (NFS), presumably because the operating system vendor does not offer anything else. NFS exac- erbates all of the above problems. Some NFS implementations don't provide any reliable locking mechanism. With mbox and mh formats, if two machines deliver mail to the same user, or if a user reads mail anywhere except the delivery machine, the user's mail is at risk. maildir works without trouble over NFS. THE MAILDIR STRUCTURE
A directory in maildir format has three subdirectories, all on the same filesystem: tmp, new, and cur. Each file in new is a newly delivered mail message. The modification time of the file is the delivery date of the message. The message is delivered without an extra UUCP-style From_ line, without any >From quoting, and without an extra blank line at the end. The message is normally in RFC 822 format, starting with a Return-Path line and a Delivered-To line, but it could contain arbitrary binary data. It might not even end with a newline. Files in cur are just like files in new. The big difference is that files in cur are no longer new mail: they have been seen by the user's mail-reading program. HOW A MESSAGE IS DELIVERED
The tmp directory is used to ensure reliable delivery, as discussed here. A program delivers a mail message in six steps. First, it chdir()s to the maildir directory. Second, it stat()s the name tmp/time.pid.host, where time is the number of seconds since the beginning of 1970 GMT, pid is the program's process ID, and host is the host name. Third, if stat() returned anything other than ENOENT, the program sleeps for two seconds, updates time, and tries the stat() again, a limited number of times. Fourth, the program creates tmp/time.pid.host. Fifth, the program NFS-writes the message to the file. Sixth, the program link()s the file to new/time.pid.host. At that instant the message has been successfully delivered. The delivery program is required to start a 24-hour timer before creating tmp/time.pid.host, and to abort the delivery if the timer expires. Upon error, timeout, or normal completion, the delivery program may attempt to unlink() tmp/time.pid.host. NFS-writing means (1) as usual, checking the number of bytes returned from each write() call; (2) calling fsync() and checking its return value; (3) calling close() and checking its return value. (Standard NFS implementations handle fsync() incorrectly but make up for it by abusing close().) HOW A MESSAGE IS READ
A mail reader operates as follows. It looks through the new directory for new messages. Say there is a new message, new/unique. The reader may freely display the contents of new/unique, delete new/unique, or rename new/unique as cur/unique:info. See http://pobox.com/~djb/proto/maildir.html for the meaning of info. The reader is also expected to look through the tmp directory and to clean up any old files found there. A file in tmp may be safely removed if it has not been accessed in 36 hours. It is a good idea for readers to skip all filenames in new and cur starting with a dot. Other than this, readers should not attempt to parse filenames. ENVIRONMENT VARIABLES
Mail readers supporting maildir use the MAILDIR environment variable as the name of the user's primary mail directory. SEE ALSO
mbox(5), qmail-local(8) maildir(5)
All times are GMT -4. The time now is 10:19 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy