Sponsored Content
Full Discussion: Email formatting
Top Forums Shell Programming and Scripting Email formatting Post 42868 by norsk hedensk on Wednesday 5th of November 2003 05:43:52 PM
Old 11-05-2003
Email formatting

ok, does anyone know how i can strip out fields i dont want from a mail spool file (eg: /var/mail/usermailbox) and dump to standard output (or file with > filename) ?? i tried using a bunch of grep -v 's but i realized that has two main problems, first of all, if anyone types the text im grepping out it will get removed, so i could tell grep to do it only once with -m 1 and so on, but there is going to be many emails in the mailbox.

so what i need is something like this:

Code:
From joe@farragutmarine.com  Tue Nov  4 22:34:54 2003
Return-Path: <joe@farragutmarine.com>
Delivered-To: main@farragutmarine.com
Received: from 192.168.1.103 (dynip4 [192.168.1.103])
        by farragutmarine.com (Postfix) with ESMTP id 0CD261700B
        for <main@farragutmarine.com>; Tue,  4 Nov 2003 22:34:54 -0500 (EST)
From: joe@farragutmarine.com
To: main@farragutmarine.com
Subject: This is a test
Date: Tue, 4 Nov 2003 23:12:40 -0500
User-Agent: KMail/1.5.1
MIME-Version: 1.0
Content-Type: text/plain;
  charset="us-ascii"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Message-Id: <200311042312.40075.joe@farragutmarine.com>

This is a test, lets see if i can get this thing working.

now please keep in mind that there will be multiple emails in the mailbox. the fields in BOLD are the fields id like to keep.


i dont expect anyone to write out a whole script for me, just someone to point me in the right direction.

thanks !
 

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Unable to send eMail from a UNIX-Host ( using mailx ) to a Outlook-email-addres(Win)

Hi A) I am able to send eMail using mailx from a UNIX ( solaris 8 ) host to my Outlook-email-ID : FName.Surname@Citigroup.com ( This is NOT my actual -eMail-ID). But in Outlook the "From :" eMail address is displayed as " usr1@unix-host1.unregistered.email.citicorp.com " .i.e the words... (2 Replies)
Discussion started by: Vetrivela
2 Replies

2. UNIX for Dummies Questions & Answers

Send email where # is in the email address - Using Unix

Hi All, How do I send an email using malix where email address contains a #. I have a email address like this : #test@test.com I want to send email like malix -s "TEST" #test@test.com < SOMEFILE I tried \# but doesn't work. Please let me know how we can achieve this? I am in... (1 Reply)
Discussion started by: jingi1234
1 Replies

3. Solaris

Send an email from Solaris using Linux email server

Hello everyone I have a problem and I need your help: I have a Solaris 10 and Solaris 8 UNIX Servers, and Linux Centos4 as email server. I need send an email from Solaris servers preferably using Centos4 email server. I have no mail service configured in my Solaris computers (1 Reply)
Discussion started by: aflores
1 Replies

4. UNIX for Dummies Questions & Answers

new to ldap, send email to a ou or group, and see a list from email client

hi, i'm running openldap on ubuntu 10.04, creating new items with apache directory studio (windows version). i use the ldap just as an address book to our small office (email clients are windows live mail 2009, 2011, microsoft outlook 2007 and 2010). a. i cant see a list of the contacts,... (0 Replies)
Discussion started by: V4705
0 Replies

5. Shell Programming and Scripting

Using top command to email if process is exceeding 25% and sending an email alert if so

This is my first time writing a script and Im having some trouble, Im trying to use the top command to monitor processes and the amount of CPU usage they require, my aim is to get an email if a process takes over a certain percentage of CPU usage I tried grep Obviosly that hasnt worked, Any... (8 Replies)
Discussion started by: jay02
8 Replies

6. Windows & DOS: Issues & Discussions

email from *nix to Exchange - text formatting issue

Oracle Linux 5.6 x-86-64 (Red Hat derivitive) I have several shell scripts that capture output to a log file, then use that log file as the source of an email. For a very simplified example: echo Today is `date` >> $logfile /bin/mail -s "$subject" "$sendto" < $logfile (yes, $subject... (6 Replies)
Discussion started by: edstevens
6 Replies

7. Shell Programming and Scripting

[Solved] Sending a HTML email from cli loses formatting.

Hi, I have a .sh file, to email a report of our backups from a linux machine. It looks like this (minus a few bits): echo "HELO $host.$domain" sleep 1 echo "mail from: vdrreport@$domain" sleep 1 echo "rcpt to:$mailto" sleep 1 echo "data" sleep 1 echo "subject: $host VDR-Report... (2 Replies)
Discussion started by: cognito
2 Replies

8. UNIX for Dummies Questions & Answers

Formatting The Email Output

Hello All, When i use the single quotes around the variables i am getting each line in the array as seperate in the email as shown in code2 & output2. But i don't want those single quotes to be printed but each array element should be printed as seperate line as when i remove those single quotes... (1 Reply)
Discussion started by: Ariean
1 Replies

9. UNIX for Dummies Questions & Answers

Email formatting gets disturbed because of screen resolution

Hi friends, I have written a shell script which send a report to email address everyday. The report is generated on UNIX server every day, Generated report is sent to 25 users through cron. All 25 users have set different screen resolution for their monitor. The email looks wel formatted for... (4 Replies)
Discussion started by: Nakul_sh
4 Replies

10. Shell Programming and Scripting

Getting email output in single line with out space in email

I have tried below email method and i am getting every thing in single line . i have put echo to provide space, but it is not helping my code ( echo "From: $FROM" echo "To: $MAILTO" echo "CC: $CC" echo "Subject: $SUBJECT" echo "MIME-Version: 1.0" echo 'Content-Type: multipart/mixed;... (6 Replies)
Discussion started by: mirwasim
6 Replies
Email::Filter(3pm)					User Contributed Perl Documentation					Email::Filter(3pm)

NAME
Email::Filter - Library for creating easy email filters SYNOPSIS
use Email::Filter; my $mail = Email::Filter->new(emergency => "~/emergency_mbox"); $mail->pipe("listgate", "p5p") if $mail->from =~ /perl5-porters/; $mail->accept("perl") if $mail->from =~ /perl/; $mail->reject("We do not accept spam") if $mail->subject =~ /enlarge/; $mail->ignore if $mail->subject =~ /boring/i; ... $mail->exit(0); $mail->accept("~/Mail/Archive/backup"); $mail->exit(1); $mail->accept() DESCRIPTION
This is another module produced by the "Perl Email Project", a reaction against the complexity and increasing bugginess of the "Mail::*" modules. It replaces "Mail::Audit", and allows you to write programs describing how your mail should be filtered. TRIGGERS
Users of "Mail::Audit" will note that this class is much leaner than the one it replaces. For instance, it has no logging; the concept of "local options" has gone away, and so on. This is a deliberate design decision to make the class as simple and maintainable as possible. To make up for this, however, "Email::Filter" contains a trigger mechanism provided by Class::Trigger, to allow you to add your own functionality. You do this by calling the "add_trigger" method: Email::Filter->add_trigger( after_accept => &log_accept ); Hopefully this will also help subclassers. The methods below will list which triggers they provide. ERROR RECOVERY
If something bad happens during the "accept" or "pipe" method, or the "Email::Filter" object gets destroyed without being properly handled, then a fail-safe error recovery process is called. This first checks for the existence of the "emergency" setting, and tries to deliver to that mailbox. If there is no emergency mailbox or that delivery failed, then the program will either exit with a temporary failure error code, queuing the mail for redelivery later, or produce a warning to standard error, depending on the status of the "exit" setting. METHODS
new Email::Filter->new(); # Read from STDIN Email::Filter->new(data => $string); # Read from string Email::Filter->new(emergency => "~simon/urgh"); # Deliver here in case of error This takes an email either from standard input, the usual case when called as a mail filter, or from a string. You may also provide an "emergency" option, which is a filename to deliver the mail to if it couldn't, for some reason, be handled properly. Hint If you put your constructor in a "BEGIN" block, like so: use Email::Filter; BEGIN { $item = Email::Filter->new(emergency => "~simon/urgh"); } right at the top of your mail filter script, you'll even be protected from losing mail even in the case of syntax errors in your script. How neat is that? This method provides the "new" trigger, called once an object is instantiated. exit $mail->exit(1|0); Sets or clears the 'exit' flag which determines whether or not the following methods exit after successful completion. The sense-inverted 'noexit' method is also provided for backwards compatibility with "Mail::Audit", but setting "noexit" to "yes" got a bit mind-bending after a while. simple $mail->simple(); Gets and sets the underlying "Email::Simple" object for this filter; see Email::Simple for more details. header $mail->header("X-Something") Returns the specified mail headers. In scalar context, returns the first such header; in list context, returns them all. body $mail->body() Returns the body text of the email from to cc bcc subject received $mail-><header>() Convenience accessors for "header($header)" ignore Ignores this mail, exiting unconditionally unless "exit" has been set to false. This method provides the "ignore" trigger. accept $mail->accept(); $mail->accept(@where); Accepts the mail into a given mailbox or mailboxes. Unix "~/" and "~user/" prefices are resolved. If no mailbox is given, the default is determined according to Email::LocalDelivery: $ENV{MAIL}, /var/spool/mail/you, /var/mail/you, or ~you/Maildir/. This provides the "before_accept" and "after_accept" triggers, and exits unless "exit" has been set to false. reject $mail->reject("Go away!"); This rejects the email; if called in a pipe from a mail transport agent, (such as in a ~/.forward file) the mail will be bounced back to the sender as undeliverable. If a reason is given, this will be included in the bounce. This calls the "reject" trigger. "exit" has no effect here. pipe $mail->pipe(qw[sendmail foo@bar.com]); Pipes the mail to an external program, returning the standard output from that program if "exit" has been set to false. The program and each of its arguments must be supplied in a list. This allows you to do things like: $mail->exit(0); $mail->simple(Email::Simple->new($mail->pipe("spamassassin"))); $mail->exit(1); in the absence of decent "Mail::SpamAssassin" support. If the program returns a non-zero exit code, the behaviour is dependent on the status of the "exit" flag. If this flag is set to true (the default), then "Email::Filter" tries to recover. (See "ERROR RECOVERY") If not, nothing is returned. PERL EMAIL PROJECT
This module is maintained by the Perl Email Project <http://emailproject.perl.org/wiki/Email::Filter> COPYRIGHT
Copyright 2003, Simon Cozens <simon@cpan.org> LICENSE
You may use this module under the terms of the BSD, Artistic, or GPL licenses, any version. AUTHOR
Casey West, "casey@geeknest.com" Simon Cozens, "simon@cpan.org" perl v5.10.0 2008-09-15 Email::Filter(3pm)
All times are GMT -4. The time now is 01:03 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy