Re: Delete mails by subject using mailx ?



materik wrote:
I want to delete mail by subject , i.e. "delete all mails from my
mailbox having subject xyz"

I want to run this using a crontab scheduled script.


How can I do this ? Im using mailx and Solaris 8.


TIA Materik


You could do this using a combination of formail and procmail

Cron job: to run the script at say 4:23am

23 4 * * * customscript

-=-=-=-=-
In the custom script have something like this which directs formail to parse the messages on stdin expecting mail box format and to feed each message separately to it's own procmail process so that the subject headers can be checked separately. The procmail process would need to have a custom.rc file to use in this case.
---------
#!/bin/bash

if ! [ -f /path/to/oldmailbox.lock ]; then
touch /path/to/oldmailbox.lock
else
echo "oldmailbox is locked. Script aborted"
exit 1;
fi

# process the oldmailbox messages into newmailbox using procmail to
# delete messages containing xyz in the subject header
cat /path/to/oldmailbox |formail -s procmail /path/to/custom.rc

# replace the oldmailbox with newmailbox.
mv newmailbox oldmailbox

# remove the lockfile
rm /path/to/oldmailbox.lock

-=-=-=-=-
In the procmail custom.rc file
---------

NEWMAILBOX="/home/${LOGNAME}/mail/newmailbox"

# delete messages containing xyz in the subject
# or you could just move them to a different folder.
:0
* ^Subject:.*xyz.*$
/dev/null

# save all messages not containing xyz in the subject to the
# newmailbox folder
:0:
${NEWMAILBOX}


Hope this helps.
Garen
.



Relevant Pages

  • Re: problems with grep
    ... I want to write a script that will look at other scripts and find ... And why does this match xyz but not abc ???? ...
    (comp.unix.shell)
  • Re: problems with grep
    ... I want to write a script that will look at other scripts and find ... And why does this match xyz but not abc ???? ...
    (comp.unix.shell)
  • Re: ksh script to parse name/value pairs
    ... On 2009-04-14, inetquestion wrote: ... I started working on the script below, but felt I was going in the ... data="987654321 xyz ... Each name-value pair is now a positional parameter: ...
    (comp.unix.shell)
  • Expect: spawned process in sleep state (log_file problem?)
    ... I have a working Expect script which spawns another tcl script ... #-- First, spawn the xyz script ... puts "abc is $abc" ... the xyz script ran in background. ...
    (comp.lang.tcl)