copy e-mails from one mailbox to another each week

Discuss your pilot or production implementation with other Zimbra admins or our engineers.
Post Reply
lethargos
Posts: 19
Joined: Thu Oct 20, 2016 12:32 pm

copy e-mails from one mailbox to another each week

Post by lethargos »

Hi,
I'm trying to copy weekly e-mails from one account to another. I don't want to simply give access to the mailbox to a certain user, because I want the e-mails to be persistent in case the user whose mailbox I copy the e-mails from chooses to delete them.
I came up with the following script:

Code: Select all

lweek=$(date -d "last week" +"%Y%m%d%H%M%S")

for mail in /opt/zimbra/store/0/2/msg/0/*
do
        echo $mail
        outp="$(awk '/^Date/ && $5 ~ /^[1-2][0-9]+$/ { print $3, $4, $5, $6; exit }' $mail)"
        maildate=$(date -d "$outp" +"%Y%m%d%H%M%S")
                if [ $maildate -gt $lweek ]; then
                /opt/zimbra/bin/zmmailbox -z -m destination_account@domain.com addMessage /Inbox/tempo $mail
                else echo "not applicable for mail"
                fi
done
The problem with this script is that the zmmailbox addMessage command will copy e-mails indiscriminately, even if they're already there. So I might end up with duplicates and I can't simply count only on the fact that the script will run exactly in a week's time. Any ideas how I could do a check and add another filter/condition so that it copies only the e-mails that aren't already there?

Thanks!
User avatar
DualBoot
Elite member
Elite member
Posts: 1326
Joined: Mon Apr 18, 2016 8:18 pm
Location: France - Earth
ZCS/ZD Version: ZCS FLOSS - 8.8.15 Mutli servers
Contact:

Re: copy e-mails from one mailbox to another each week

Post by DualBoot »

Hello,

why do not you use archiving provided by Zimbra NE ?

Regards,
lethargos
Posts: 19
Joined: Thu Oct 20, 2016 12:32 pm

Re: copy e-mails from one mailbox to another each week

Post by lethargos »

Hi,

I don't really understand how archiving could help me in this case. I'm trying to copy e-mails from one account to another and do it automatically. Can you expand on that?
phoenix
Ambassador
Ambassador
Posts: 27278
Joined: Fri Sep 12, 2014 9:56 pm
Location: Liverpool, England

Re: copy e-mails from one mailbox to another each week

Post by phoenix »

lethargos wrote:I'm trying to copy weekly e-mails from one account to another. I don't want to simply give access to the mailbox to a certain user, because I want the e-mails to be persistent in case the user whose mailbox I copy the e-mails from chooses to delete them.
Why don't you create in the 'source' email account a folder that contains the email you want to share, you can do that with a filter (copy or move), and when you've done that share the folder (read only) with the user that needs to read them? It's far simpler, IMO, than writing scripts and the mail can never be deleted by someone that only has read access.
Regards

Bill

Rspamd: A high performance spamassassin replacement

Per ardua ad astra
lethargos
Posts: 19
Joined: Thu Oct 20, 2016 12:32 pm

Re: copy e-mails from one mailbox to another each week

Post by lethargos »

Well, as I already explained in my initial post, I want copies of the e-mails in case the user whom I'm copying the e-mails from tries to delete them. If I share it read only, I would only prevent the user whom I'm copying the e-mails to to delete them, which I don't care about.
Moreover, I'd also want a little bit of discretion (even if it's actually rather open at the same time), so I wouldn't want to create another folder in the user's mailbox so that he can see it.
On top of that, I'm guessing that creating a filter would presuppose that the user whom I'm copying e-mails from is going to see in the webmail. I think that I might be able to do it using bash scripting only, so that the zmmailbox addMessage command would only apply to the e-mails that haven't been already copied. But I'm not sure how to do that.
phoenix
Ambassador
Ambassador
Posts: 27278
Joined: Fri Sep 12, 2014 9:56 pm
Location: Liverpool, England

Re: copy e-mails from one mailbox to another each week

Post by phoenix »

Then, as dualboot has said, implement an archiving solution - there are plenty of open source solutions available and some of them allow user access to those messages. If this is a business scenario then it's possible you're legally required to keep copies of email, in any case it's prudent to archive email for your own peace of mind.
Regards

Bill

Rspamd: A high performance spamassassin replacement

Per ardua ad astra
User avatar
DualBoot
Elite member
Elite member
Posts: 1326
Joined: Mon Apr 18, 2016 8:18 pm
Location: France - Earth
ZCS/ZD Version: ZCS FLOSS - 8.8.15 Mutli servers
Contact:

Re: copy e-mails from one mailbox to another each week

Post by DualBoot »

Zimbra archiving allow to copy every mail which passed through the mailbox on a second dedicated mailbox.
No need to script.
lethargos
Posts: 19
Joined: Thu Oct 20, 2016 12:32 pm

Re: copy e-mails from one mailbox to another each week

Post by lethargos »

Is this also available in the non-commercial version? I'm using 8.6.0_GA_1162.NETWORK. Could you offer a link?
User avatar
DualBoot
Elite member
Elite member
Posts: 1326
Joined: Mon Apr 18, 2016 8:18 pm
Location: France - Earth
ZCS/ZD Version: ZCS FLOSS - 8.8.15 Mutli servers
Contact:

Re: copy e-mails from one mailbox to another each week

Post by DualBoot »

Nope, only for Network Edition.
Post Reply