Script to delete emails based on subject

Discussion in 'Programming/Scripts' started by fujipadam, Sep 2, 2009.

  1. fujipadam

    fujipadam New Member


    I would like your input and advice on dealing with some email issues.

    We have some 40,000 emails in one of our mailboxes ([email protected]) with a single subject ("Mail delivery failed: returning message to sender")

    I would like to delete all of these messages with this subject. I am not able to do this using regular email clients such as outlook or thunderbird (extremely time consuming.)

    Is there a way I could do this via command line or a script?

    I would appreciate any input and help in this regard.


  2. id10t

    id10t Member

    Are you using Maildir or mbox format?
  3. fujipadam

    fujipadam New Member

    Hi - I am using Maildir format
  4. id10t

    id10t Member

    each message has a individual file, and you can grep for the subject line, cut the first field delimited by a colon and then delete that list of files.
  5. fujipadam

    fujipadam New Member

    Thanks id10t - I had to use xargs since the list of files were too large for grep to handle - but overall the approach seems to work - will test it out a couple of times and then use it on the production machine
  6. DoctorMendel

    DoctorMendel New Member

    Thanks for starting that topic.
  7. RogerBennett

    RogerBennett New Member

    I have already using this script looking for new
  8. biggdog

    biggdog Member HowtoForge Supporter

    I may not totally understand but I know I have a problem that is like yours although not 40,000 of them but a lot over 1,000 I create a rule in Outlook and also mark it as read and send it to the trash.
    I would like to see your script if and when you get this done and tested. I would like to see if it can help in our situation.
    Thanks for the post / question.
  9. zapper911

    zapper911 New Member

    If you have access to mail server, you can grep/find through mailbox for your text and delete matched files. This approach will work only if your mail server store each message in individual file.
  10. Micke Picton

    Micke Picton New Member

    really it is a nice topic thanks for staring you
  11. ohhteriiii

    ohhteriiii New Member

    Thanks for starting that topic.


Share This Page