Results 1 to 9 of 9

Thread: [SOLVED] delete mails via cli based on date

Hybrid View

  1. #1
    Join Date
    Nov 2008
    Location
    belgium
    Posts
    11
    Rep Power
    7

    Default [SOLVED] delete mails via cli based on date

    Hi,

    is it possible to delete all mail from a specific user before a specific date?
    now i have to go into the users mails, use find and then delete per 100 mails

    I need this because the migration went wrong and I have to redo this. If I don't delete the old mails first i got doubles.

  2. #2
    Join Date
    Nov 2009
    Location
    Columbus, Ohio
    Posts
    9
    Rep Power
    6

    Default

    A co-worker made a script that I then modified it to ask for variables like the account name, folder, etc.

    It then uses zmmailbox to search for emails meeting the criteria that you put in the variables, uses sed to trim and create a temp file containing the messageID of the messages to delete, then uses zmmailbox again to parse the temp file, and delete the messageIDs.

    I've found that even though I've set the search -l to 100000, it only deletes approx 2500 at a time. I'm not sure why. That's why it prompts for a loop in the end.

    Remember to su to zimbra.

    Feel free to rip me apart for my week skills. I'm sure there is plenty of room for improvement, and I'd like to hear it.

    Here it is:

    #!/bin/bash
    #version .1
    #

    ZIMBRA_BIN=/opt/zimbra/bin
    echo "Enter the username.:"
    read THEACCOUNT

    echo "Enter the time that you would like to delete messages up to, in mm/dd/yy format. Example 04/10/09:"
    read THEDATE

    echo "What folder would you like to delete these messages from?:"
    read THEFOLDER

    echo "You will now be deleting Messages from the $THEFOLDER folder up to $THEDATE for $THEACCOUNT."
    echo "Do you want to continue? (y/N): "
    read ADD

    themagic ()
    {
    touch /tmp/deleteOldMessagesList.txt
    for i in `$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT search -l 100000 "in:/$THEFOLDER (before:$THEDATE)" | grep conv | sed -e "s/^\s\s*//" | sed -e "s/\s\s*/ /g" | cut -d" " -f2`
    do
    if [[ $i =~ [-]{1} ]]
    then
    MESSAGEID=${i#-}
    echo "deleteMessage $MESSAGEID" >> /tmp/deleteOldMessagesList.txt
    else
    echo "deleteConversation $i" >> /tmp/deleteOldMessagesList.txt
    fi
    done

    $ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT < /tmp/deleteOldMessagesList.txt >> /tmp/process.log
    rm -f /tmp/deleteOldMessagesList.txt
    echo "Completed. Run again for same user?"
    read ADD
    }


    while expr "$ADD" : ' *[Yy].*'
    do themagic
    done

  3. #3
    Join Date
    Jan 2008
    Posts
    223
    Rep Power
    7

    Default

    Quote Originally Posted by brumdo View Post
    A co-worker made a script that I then modified it to ask for variables like the account name, folder, etc.

    It then uses zmmailbox to search for emails meeting the criteria that you put in the variables, uses sed to trim and create a temp file containing the messageID of the messages to delete, then uses zmmailbox again to parse the temp file, and delete the messageIDs.

    I've found that even though I've set the search -l to 100000, it only deletes approx 2500 at a time. I'm not sure why. That's why it prompts for a loop in the end.

    Remember to su to zimbra.

    Feel free to rip me apart for my week skills. I'm sure there is plenty of room for improvement, and I'd like to hear it.

    Here it is:

    #!/bin/bash
    #version .1
    #

    ZIMBRA_BIN=/opt/zimbra/bin
    echo "Enter the username.:"
    read THEACCOUNT

    echo "Enter the time that you would like to delete messages up to, in mm/dd/yy format. Example 04/10/09:"
    read THEDATE

    echo "What folder would you like to delete these messages from?:"
    read THEFOLDER

    echo "You will now be deleting Messages from the $THEFOLDER folder up to $THEDATE for $THEACCOUNT."
    echo "Do you want to continue? (y/N): "
    read ADD

    themagic ()
    {
    touch /tmp/deleteOldMessagesList.txt
    for i in `$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT search -l 100000 "in:/$THEFOLDER (before:$THEDATE)" | grep conv | sed -e "s/^\s\s*//" | sed -e "s/\s\s*/ /g" | cut -d" " -f2`
    do
    if [[ $i =~ [-]{1} ]]
    then
    MESSAGEID=${i#-}
    echo "deleteMessage $MESSAGEID" >> /tmp/deleteOldMessagesList.txt
    else
    echo "deleteConversation $i" >> /tmp/deleteOldMessagesList.txt
    fi
    done

    $ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT < /tmp/deleteOldMessagesList.txt >> /tmp/process.log
    rm -f /tmp/deleteOldMessagesList.txt
    echo "Completed. Run again for same user?"
    read ADD
    }


    while expr "$ADD" : ' *[Yy].*'
    do themagic
    done
    IT works , in My Case it gives me 1000 message a time.Lookslike some parameter that limits it give 1000 or 2500 message at a time to be searched at a time.

  4. #4
    Join Date
    Nov 2013
    Posts
    1
    Rep Power
    2

    Default I tried same script but it's not working

    Hi Guys,

    I tried same script but it's not working..

    If I enter what folder I want to delete after that remaining loops are not working. Automatically comes with command prompt.

    Please help................

  5. #5
    Join Date
    Sep 2011
    Posts
    39
    Rep Power
    4

    Default

    Hi there,

    Happy new year to all of you guys.

    Thank for this great script.
    Unfortunately I do have an error as well.

    ERROR: zclient.CLIENT_ERROR (limit must be 1-1000)

    Anyone can help me to fix this plese ?

  6. #6
    Join Date
    Mar 2014
    Posts
    1
    Rep Power
    1

    Default

    Quote Originally Posted by Ranjithkumar View Post
    Hi Guys,

    I tried same script but it's not working..

    If I enter what folder I want to delete after that remaining loops are not working. Automatically comes with command prompt.

    Please help................
    1. You mention command prompt, this is a *nix script. Not for Windows?
    2. Did you su to zimbra?
    Quote Originally Posted by backpacker77
    Hi there,

    Happy new year to all of you guys.

    Thank for this great script.
    Unfortunately I do have an error as well.

    ERROR: zclient.CLIENT_ERROR (limit must be 1-1000)

    Anyone can help me to fix this plese ?
    And for you I'm guessing the error is here, which means you need to change that 100k to 1k
    Code:
    for i in `$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT search -l 100000 "in:/$THEFOLDER (before:$THEDATE)" | grep conv | sed -e "s/^\s\s*//" | sed -e "s/\s\s*/ /g" | cut -d" " -f2`

  7. #7
    Join Date
    Sep 2011
    Posts
    39
    Rep Power
    4

    Default

    And for you I'm guessing the error is here, which means you need to change that 100k to 1k
    Code:
    for i in `$ZIMBRA_BIN/zmmailbox -z -m $THEACCOUNT search -l 100000 "in:/$THEFOLDER (before:$THEDATE)" | grep conv | sed -e "s/^\s\s*//" | sed -e "s/\s\s*/ /g" | cut -d" " -f2`
    [/QUOTE]

    Yes indeed. Thanks

  8. #8
    Join Date
    Nov 2008
    Location
    belgium
    Posts
    11
    Rep Power
    7

    Default

    thx this works!

  9. #9
    Join Date
    Jan 2010
    Posts
    1
    Rep Power
    5

    Default

    OK! That's great! It's work very well

Similar Threads

  1. Delete spam mails from queue
    By sandiphw in forum Administrators
    Replies: 15
    Last Post: 11-01-2012, 11:07 AM
  2. Zimbra fails after working for 2 weeks
    By Linsys in forum Administrators
    Replies: 10
    Last Post: 10-07-2008, 01:42 AM
  3. Replies: 1
    Last Post: 10-03-2008, 03:30 PM
  4. Delete Mails on Hold
    By yusufu in forum Administrators
    Replies: 0
    Last Post: 06-06-2008, 05:38 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
  •