LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 06-10-2015, 08:46 AM   #1
markkus619
LQ Newbie
 
Registered: Jun 2015
Location: Brazil
Distribution: CentOS, Fedora
Posts: 5

Rep: Reputation: Disabled
How to delete emails based on subject?


Hi,

Theres a way to delete all emails based on subject on linux?

I need remove more than 100k os mails with subject:

Mail delivery failed: returning message to sender
 
Old 06-10-2015, 11:41 AM   #2
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
what kind of mailer do you have? For example using thunderbird you can easily create a filter to do that.
 
Old 06-10-2015, 12:15 PM   #3
markkus619
LQ Newbie
 
Registered: Jun 2015
Location: Brazil
Distribution: CentOS, Fedora
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi

Thanks for attention

I need remove this via shell from the server...

I'm using something like:

find . -type f -exec grep -i "Mail delivery failed: returning message to sender" -exec rm -v {} \;
grep: Mail delivery failed: returning message to sender: Arquivo ou diretório não encontrado

find $1 . -type f -exec grep -i "Mail delivery failed: returning message to sender" {} \; | xargs rm -v $2
for RM in $(find . -type f -exec grep -i "Mail delivery failed: returning message to sender" {} \; do rm -v $RM ; done



But i can't figure out how to remove the file. Just how to find the subject...
 
Old 06-10-2015, 01:30 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by markkus619 View Post
I'm using something like:

Code:
find . -type f -exec grep -i "Mail delivery failed: returning message to sender" -exec rm -v {} \;
grep: Mail delivery failed: returning message to sender: Arquivo ou diretrio no encontrado

Code:
find $1 . -type f -exec grep -i "Mail delivery failed: returning message to sender" {} \; | xargs rm -v $2
for RM  in $(find . -type f -exec grep -i "Mail delivery failed: returning message to sender" {} \;); do rm -v $RM ;
done
Not gonna work, but go ahead and see.
IF you had thunderbird, you could "see" where in your Tbird setup these messages occur using:
Code:
find .thunderbird/ -type f -exec grep -il "Mail delivery failed: returning message to sender" {} \;
do NOT do any -exec on anything found since it will nuke the folder it finds in and not the actual message.

Thunderbird (all of mozilla-land, it seems) uses sqllite databases for message storage, so nuking them should be done from
inside the Thunderbird program.
Code:
file .thunderbird/uvpc4uva.default/global-messages-db.sqlite
.thunderbird/RanDOM.default/global-messages-db.sqlite: SQLite 3.x database, user version 30
 
Old 06-10-2015, 06:04 PM   #5
schlabs
Member
 
Registered: Aug 2007
Posts: 36

Rep: Reputation: 4
if i can think in high voice.... i think that in your place i do a script based on:
cd maildir/folder
grep -in "subject" * |grep -in "subject to delete" >a.txt

If all work fine you will get into "a.txt"the list of matching files.

My script can contain error there is not intended to copy/paste, is to give a idea about direction that i take in your place.
 
1 members found this post helpful.
Old 06-11-2015, 09:07 AM   #6
markkus619
LQ Newbie
 
Registered: Jun 2015
Location: Brazil
Distribution: CentOS, Fedora
Posts: 5

Original Poster
Rep: Reputation: Disabled
Thanks!

Hi people.

Maybe i not expressing myself properly. I'm using centos with exim. No email client. Thanks for efforts.


Quote:
Originally Posted by schlabs View Post
if i can think in high voice.... i think that in your place i do a script based on:
cd maildir/folder
grep -in "subject" * |grep -in "subject to delete" >a.txt

If all work fine you will get into "a.txt"the list of matching files.

My script can contain error there is not intended to copy/paste, is to give a idea about direction that i take in your place.


Hi schlabs

Thanks for help!

That was what i was looking for.

Now i can take the name of mailfile by the subject.

Soon as possible i'll make a script and post here.

I was a little confuse how to take the name of file by subject. But with your help now i can figure out how to.
 
Old 06-11-2015, 10:28 AM   #7
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by markkus619 View Post
But with your help now i can figure out how to.
Don't have to.
To delete all queued messages containing a certain string in the body < for exim only
 
Old 06-12-2015, 06:09 AM   #8
schlabs
Member
 
Registered: Aug 2007
Posts: 36

Rep: Reputation: 4
Quote:
Originally Posted by markkus619 View Post
Hi people.

Maybe i not expressing myself properly. I'm using centos with exim. No email client. Thanks for efforts.






Hi schlabs

Thanks for help!

That was what i was looking for.

Now i can take the name of mailfile by the subject.

Soon as possible i'll make a script and post here.

I was a little confuse how to take the name of file by subject. But with your help now i can figure out how to.
grep -in in human mode say: show me the name of the file and the line with matching string, and case insensitive. So with the first grep you will get all files with "subject" string, and will show the line of subject. So the first grep will show all emails subject and their filename.

The second grep make the real filter showing only the files that matching "spam to erase"or "mail returned" or etc.

After both grep you will get a list of filenames that meet your requirements. Some like :
mailfile12345:25:Subject: mail returned
or
mail_filename:number of line:matching text

A last step is redirect the screen to any file, so you will get a list of files to erase.

Actually i do some similar, i create a folder SPAM email. When the user put a email here i look (grep) email provider of spammer, ip provider of spammer, and domains involved. This automatically update the spam filter.

Best Regards
 
1 members found this post helpful.
Old 06-16-2015, 10:13 AM   #9
markkus619
LQ Newbie
 
Registered: Jun 2015
Location: Brazil
Distribution: CentOS, Fedora
Posts: 5

Original Poster
Rep: Reputation: Disabled
Hi

I found a way with this command. To remove all in the current folder.

grep -in "Mail delivery failed: returning message to sender" * | grep -in "Mail delivery failed: returning message to sender" | rm -rf $(awk -F ":" '{print $2}')

Thanks for the help.
 
Old 06-16-2015, 10:28 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,850

Rep: Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309Reputation: 7309
Sorry guy, do you mean the same grep two times and piped into an rm?
I would rather suggest you to look for another solution, this is not the right way.
 
Old 06-16-2015, 11:01 AM   #11
markkus619
LQ Newbie
 
Registered: Jun 2015
Location: Brazil
Distribution: CentOS, Fedora
Posts: 5

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
Sorry guy, do you mean the same grep two times and piped into an rm?
I would rather suggest you to look for another solution, this is not the right way.
OK.

Any suggestion??

Later i'll try something...
 
Old 06-16-2015, 11:01 AM   #12
average_user
Member
 
Registered: Dec 2010
Location: Warsaw, Poland
Distribution: Slackware
Posts: 560

Rep: Reputation: 220Reputation: 220Reputation: 220
I did something similar myself recently using procmail, one of the best mail filtering programs out there by looping through all e-mails and executing procmail on them and removing an e-mail afterwards like this:
Code:
#!/usr/bin/env sh

set -e

for dir in cur new; do
    find $INPUTMAILDIR/$dir -type f | while read file; do
        procmail < $file
        rm $file
    done
done
You need to add a correct rule to your ~/.procmailrc before running this script. The rule could look like this:
Code:
:0:
* ^Subject:.*Mail delivery failed: returning message to sender*
/dev/null
BTW, I also recommend procmail as an every-day filtering program for your e-mail. You can make it execute an arbitrary action based on e-mail sender, subject, body or attachments.

Last edited by average_user; 06-16-2015 at 11:02 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Postfix - Reject Emails w/ No Subject? carlosinfl Linux - Server 2 08-24-2018 11:34 AM
Downloading emails with specific subject only fandar Linux - Software 1 03-06-2013 10:20 AM
How to see the subject of emails queued voltron81 Linux - Server 2 01-25-2010 03:13 AM
old emails in kmail unreadable ¨No Subject¨ bobinglis Linux - General 2 05-07-2005 07:18 PM
Recording subject lines in emails timjames Linux - Software 0 07-30-2003 08:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:39 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration