Results 1 to 9 of 9

Thread: Contrib: How to delete emails based on subject script

Hybrid View

  1. #1
    Join Date
    Oct 2006
    Location
    Montana
    Posts
    38
    Rep Power
    9

    Default Contrib: How to delete emails based on subject script

    This may be an old thread, but I ran into this same problem today so I thought I'd share the script I used in case someone else stumbles across this thread via a search engine like I did.

    I had a user who sent about 50mb of photographs to every one of the users in her address book. Multiple times if they were in multiple distribution lists. Since I have multiple remote sites that use my Zimbra server via a couple shared DSL lines, this clobbered all the remote locations.

    I took examples from a couple of the sources linked earlier in the thread (bdial's psudocode and King0770's script), and combined them. It runs about 35 accounts per minute on my system, so it wouldn't scale too well for larger installations, but it is still way faster than doing it by hand.

    The expected inputs are the from_username and subject. The script steps through each account on the server and deletes any messages it finds from the user provided and with the subject provided.

    I ran: ./rm_mssg.sh Smart_User "(no subject)"
    Smart_User isn't a big fan of filling in the subject when she sends emails so there was some collateral damage, but I didn't care at that point.

    Code:
    #!/bin/bash
    # rm_mssg.sh user subject
    
    if [ -z "$2" ]; then
     echo "usage:  rm_message.sh <fromuser_name> <subject>"
     echo "  Rummages through all mail boxes looking for messages from <fromuser_name> with subject=<subject>"
     echo "  Example: ./rm_mssg.sh butthead_user rems "
     echo "  Put double-quotes around multi-word subjects"
     exit 0
    else
     addr=$1
     subject=$2
    
     for usractnopac in `zmprov gaa`
      do
       echo "Searching $usractnopac  for Subject:  $subject From: $addr"
       for msg in `zmmailbox -z -m "$usractnopac" s -l 999 -t message "from:$addr subject:$subject"|awk '{ if (NR!=1) {print}}' |
          grep -v -e Id -e "-" -e "^$" | awk '{ print $2 }'`
          do
            echo "Removing "$msg""
            zmmailbox -z -m $usractnopac dm $msg
          done
       done
    fi
    Last edited by pacsteel; 01-20-2010 at 04:58 PM. Reason: attribution
    Production: 5.0.18_GA_3011.UBUNTU8 FOSS Ubuntu 8.04 LTS
    Tested: 7.1.4_GA_2555.UBUNTU10_64 NETWORK edition Ubuntu 10.04.4 LTS
    Left Zimbra for a different product in 2011, thinking about coming back.

  2. #2
    Join Date
    Jul 2007
    Location
    Baltimore
    Posts
    1,649
    Rep Power
    11

    Default

    handy. you may want to put it on your sandbox too so people could find it searching the wiki

  3. #3
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    5

    Default

    Used this to remove a sensitive email from my mail store BUT it failed to remove the messages from the trash....does this make sense? I would like to run this script again as it is very powerful but am not a coder and can't figure out how to tweak it to delete the message when it's in the trash.

  4. #4
    Join Date
    Nov 2006
    Location
    UK
    Posts
    8,017
    Rep Power
    24

    Default

    Welcome to the forums

    Silly question but was this in your mailstore; so could you not right click and empty. Or do you mean across the entire mailstore ?

  5. #5
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    5

    Default

    I'm not sure of your question. The message was addressed to "EVERYONE" Someone replied to EVERYONE at our company and my boss asked if there was a way to delete that specific message from the sender quickly. So I found that script and ran it.

    I ran the script above as is...I did need change the line
    for usractnopac in `zmprov gaa`
    to
    for usractnopac in `zmprov -l gaa` or it wouldn't run.

  6. #6
    Join Date
    Feb 2010
    Posts
    6
    Rep Power
    5

    Default

    No it wasn't just for my email account it was for 100+ accounts.

  7. #7
    Join Date
    Jul 2007
    Location
    Baltimore
    Posts
    1,649
    Rep Power
    11

    Default

    i bet it has somethign to do with the fact that searching in trash & junk is disabled by default on most accounts and requires explicitely telling it to in advanced search

  8. #8
    Join Date
    Jul 2007
    Location
    Baltimore
    Posts
    1,649
    Rep Power
    11

    Default

    yah i think so, try doing this

    change this line

    Code:
    for msg in `zmmailbox -z -m "$usractnopac" s -l 999 -t message "from:$addr subject:$subject"|awk '{ if (NR!=1) {print}}' |
    to

    Code:
    for msg in `zmmailbox -z -m "$usractnopac" s -l 999 -t message "is:anywhere from:$addr subject:$subject"|awk '{ if (NR!=1) {print}}' |
    the is:anywhere says to search junk & trash as well

  9. #9
    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    2

    Default

    Can I use a regex for the $subject value? I'm picking up some emails that I don't want to delete. My search for info about this has come up empty...

    Thanks for any clarification.

    Owls
    Last edited by owls; 12-17-2013 at 01:04 PM.

Similar Threads

  1. Replies: 4
    Last Post: 09-16-2012, 06:33 PM
  2. Replies: 0
    Last Post: 05-07-2009, 10:35 AM
  3. zimbra opesource Backup Script Problem!
    By tashi in forum Administrators
    Replies: 4
    Last Post: 03-30-2009, 11:49 PM
  4. Zimbra Open Source Backup Help
    By ayush1440 in forum Administrators
    Replies: 8
    Last Post: 11-13-2008, 03:56 AM
  5. Delete tagged emails
    By EriSan500 in forum Users
    Replies: 1
    Last Post: 01-31-2006, 06:59 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •