Restore thousands of mails

Issue #749 resolved
Shaun created an issue

Hi. Trying to restore close to 11 000 mails. using the bulk restore, as it is all to a single user. I select all the mails on the page, then click restore. then go to the next page and repeat the process.

Is there a way to select all on every page and then restore?

Comments (7)

  1. Janos SUTO repo owner

    Not really. However the task may be done as a 2 parts job:

    1. Use pilerexport to retrieve those messages for the given user (eg. mkdir /tmp/user1; chown piler:piler /tmp/user1; cd /tmp/user1; <then run pilerexport with the proper parameters>)

    2. Send the emails to the user's email or give them as a tar or zip file to him, let him import these emails. I used to have a python script for such a mass mailing, but it's no longer in the contrib directory.

  2. Janos SUTO repo owner

    Great! If you had some time, it would be great if you could describe how you did it. Perhaps other users may appreciate it. Even if they wouldn't, I would.

  3. Shaun reporter

    Sorry about the very late reply.

    my script is very messy, but does work we have been using it for a few months If anyone wants to edit and improve it, please feel free

    get the python mailer script

    mkdir /scripts
    cd /tmp
    wget https://gist.github.com/sosukeinu/4370139/archive/09816b750b4470da3d8174ef51eb530f8c305cce.zip
    unzip 09816b750b4470da3d8174ef51eb530f8c305cce.zip
    mv 4370139-09816b750b4470da3d8174ef51eb530f8c305cce/send-message.py /scripts/
    rm 09816b750b4470da3d8174ef51eb530f8c305cce.zip
    rm -rf 4370139-09816b750b4470da3d8174ef51eb530f8c305cce
    

    Now create the export script

    vi /scripts/export.sh

    #!/bin/bash
    # Create Variables
    echo -n "from email address, followed by [ENTER]:"
    read from
    echo -n "to email address, followed by [ENTER]:"
    read to
    echo -n "start from date (yyyy-mm-dd), followed by [ENTER]:"
    read start
    echo -n "end to date (yyyy-mm-dd), followed by [ENTER]:"
    read end
    echo -n "who's email address should we restore the emails to? followed by [ENTER]:"
    read restore
    domain="piler@yourdomain.com"
    #
    # Santize
    #
    if [ "$from" = "" ]; then
        ... > /dev/null 2>&1
    else
    nfrom=$(echo "$from" | sed 's/^/-f /g')
    fi
    #
    if [ "$to" = "" ]; then
        ... > /dev/null 2>&1
    else
    nto=$(echo "$to" | sed 's/^/-r /g')
    fi
    #
    if [ "$start" = "" ]; then
        ... > /dev/null 2>&1
    else
    nstart=$(echo "$start" | sed 's/^/-a /g')
    fi
    #
    if [ "$end" = "" ]; then
        ... > /dev/null 2>&1
    else
    nend=$(echo "$end" | sed 's/^/-b /g')
    fi
    #
    #
    # Create Export Directory
    # 
    mkdir -p /tmp/export
    chmod 777 /tmp/export
    rm -f /tmp/export/*
    cd /tmp/export/
    #
    # Export EML files
    # 
    pilerexport $nstart $nend $nfrom $nto
    
    # Send eml files
    for i in $(find /tmp/export/ -name \*.eml); do 
    python /scripts/send-message.py $domain "$restore" "$i"
    done
    

    Set permissions

    chmod +x export.sh
    
  4. Log in to comment