Results 1 to 2 of 2

Thread: CLI search and delete

  1. #1
    Join Date
    Oct 2007
    Location
    Massachusetts
    Posts
    76
    Rep Power
    8

    Thumbs up CLI search and delete

    From the command line how would one search for all emails of a user with one of the fields ("From:", "To", "Subject") matching a particular string ?
    Once those messages are found, how to delete them ?
    It is sometimes inconvenient to do this from the webmail client (the search works fine but then one is forced to delete the messages in batches if there are too many messages to fit on one page)

    Thank you!.

  2. #2
    Join Date
    Aug 2010
    Location
    Melbourne, Australia
    Posts
    2
    Rep Power
    5

    Default

    To search for all emails in a user's account by a particular field matching a string...
    zmmailbox -z -m user@example.com s -t message "From: Bob"

    To delete all the results of such a search isn't quite so straightforward. You'll need a script that runs an action for each result in the above command. The below script will delete all the messages from a search for a given user as you've described...

    #!/bin/bash
    #
    # Script to delete all the messages in a user's account based on specific search criteria

    ZIMBRA_BIN=/opt/zimbra/bin

    echo "Enter the account that you would like to perform the deletion on"
    read THEACCOUNT

    echo "Enter the search string that you would like to delete (eg: Subject: *FOOBAR*) note: * = wildcard"
    read SEARCHSTRING

    echo "You will now be deleting Messages from $THEACCOUNT that match $SEARCHSTRING."
    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 "$SEARCHSTRING" | 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

    #---------end script---------------

Similar Threads

  1. Replies: 1
    Last Post: 04-02-2008, 06:10 AM
  2. Replies: 2
    Last Post: 01-22-2008, 12:42 PM
  3. delete user emails
    By zmme in forum Administrators
    Replies: 0
    Last Post: 01-20-2008, 10:03 PM
  4. Batch Delete
    By bin2hex in forum Users
    Replies: 0
    Last Post: 09-12-2006, 04:05 AM
  5. Replies: 12
    Last Post: 12-29-2005, 02:54 PM

Posting Permissions

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