Koozali.org: home of the SME Server

a bash routine for deleting email placed in the trash folder of all users

Offline purvis

  • ****
  • 567
  • +0/-0
A bash routine for deleting email placed in the trash folder of all users
The email files inside the .trash folder of all users with dates older than 180 days from the servers date will be deleted.

I wrote this bash routine to reduce the number of email files that will be scanned for viruses using another routine written by myself and your can find that at the below link.
http://forums.contribs.org/index.php/topic,49670.0.html


USE AT YOUR OWN RISK.

Code: [Select]
#!/bin/bash

find  /home/e-smith/files/users/*/Maildir/.trash -name "1*.P*.$HOSTNAME*" -mtime +180 -exec rm {} \;
exit 0


If you only want to list all the email files in only the .trash folder of all users , you can list them with this bash code
Code: [Select]
#!/bin/bash

find  /home/e-smith/files/users/*/Maildir/.trash -name "1*.*.$HOSTNAME*"
#or
#find  /home/e-smith/files/users/*/Maildir/.trash -name "1*.*.$HOSTNAME*" -exec ls -l {} \;

exit 0

 
If you want to list all the email files in of all users , you can list them with this bash code
Code: [Select]
#!/bin/bash

find  /home/e-smith/files/users/*/Maildir/* -name "1*.*.$HOSTNAME*" -exec ls -l {} \;
#or
#find  /home/e-smith/files/users/*/Maildir/* -name "1*.*.$HOSTNAME*"

exit 0

With the bash code immediately above. I found out we where receiving email to accounts that I thought were set to not receive any email from the internet but we where.
That was stopped with the below code
Code: [Select]
db accounts setprop usernamehere Visible internal
signal-event email-update

« Last Edit: March 09, 2013, 07:27:29 AM by purvis »

Offline larieu

  • ****
  • 214
  • +0/-0
I have seen over the time that the option

Code: [Select]
-exec rm {} \;
will have some issues

to avoid them I have something like

Code: [Select]
-type f -delete
which worked fine ever since I have wrote it

if everybody's life around you is better, probably yours will be better
just try to improve their life

Offline mmccarn

  • *
  • 2,626
  • +10/-0
Would it be useful to adapt the 'action' script that deletes old emails from the .junkmail folder based on a db entry?
/etc/e-smith/events/actions/purge-junkmail-folders

That script is run every evening at 11:25pm by cron based on this cron script:
/etc/cron.d/purge_junkmail


Offline purvis

  • ****
  • 567
  • +0/-0
Yes on the junk mail  script if a server manager panel option can be made for the number of days.
Set number of days to default at 7 years.
I don't know how to do that. Sorry

Offline larieu

  • ****
  • 214
  • +0/-0
mmccarn

It will be nice to have something automated to delete old "deleted but not purged" emails for the whole server, too

But until now I wasn't be able to find a reliable way to differentiate them from "non ready to be purged" emails, mostly because this emails are mixed into the same folders with normal ones.

Actually the trouble is for accounts used only form mobile phones

The mails came into inbox from where are deleted (it appears as deleted but not purged) , then copied into "Deleted Items" from where some users also delete them and there all of them remains also marked as deleted but not purged

imagine someone with a quota of 500M
The person receive 250M he/she delete them (it remain into inbox and are copied to "deleted Items" by the mobile phone app) that means 500M is reached and then he/she delete them from deleted items (in the fortunate case that the user mobile is set to see more than 30 days)

Apparently the user has no email on his account, But in reality he/she has 500M full quota used
On mobile phones (Android/iPhone/RIM(BB) ) I wasn't able to find a purge option

IF the user login into webmail and just push purge on the targeted folders - everything is ok
But this is not "easy" for them as they use only the mobile phone
if everybody's life around you is better, probably yours will be better
just try to improve their life

Offline mmccarn

  • *
  • 2,626
  • +10/-0
I found this note here in the contribs forum:
http://forums.contribs.org/index.php/topic,47275.msg233222.html#msg233222

And some notes about adding plugins to dovecot to delete expired messages, but only starting with dovecot v1.1 (or 1.2):
http://wiki1.dovecot.org/Plugins/Expire

And several mentions of 'doveadm' (from dovecot v2.x):
http://wiki2.dovecot.org/Tools/Doveadm/Expunge

dovecot --version returns 1.0.7 on my SME 8 server

Offline janet

  • ****
  • 4,812
  • +0/-0
larieu

Quote
On mobile phones (Android/iPhone/RIM(BB) ) I wasn't able to find a purge option

On iPhone there is an option of how long to keep mail in folders after deleted.
It's in the setup for each mail account (IMAP) in my case.
Settings, Mail, select account, Advanced, Deleted Messages Remove (or similar), choose Never, One day, One week, One month, 
Remember to save when exiting (select Done I think).

This may vary slightly depending on iPhone model
I expect other phones have a similar feature

In other workstation type email clients I usually select the option to Purge when leaving IMAP folders.
« Last Edit: March 12, 2013, 01:56:16 AM by mary »
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline purvis

  • ****
  • 567
  • +0/-0
There are not a lot of emails messages or users on our system for me to really figure what is happening to the email system.
We create a trash folder for emails that are deleted to be sent to when they are deleted while using the webmail web pages access.
Mostly on windows desktops, we use a email notifier that uses pop3 protocol. So our emails are deleted from the system immediate using that email notifier.
While looking over the emails that where in the trash folders, I noticed in the file name of those emails a "P" after the first period in the file name. The first character in the file name was
as "1" and in my testing, it will be a "1" for many many years to come from what I have been able recognize.

If the "P" character in the file name after the first period stands for purged(deleted) and I do not know that for sure, but assuming it is.
You should be able to modify the line where the find command is and possibly use the +mtime option to find files where the creation date is x number of days old.
Then you could make use of script to keep those deleted files to a manageable number and then have those mobile users make to change for any days less.

Offline larieu

  • ****
  • 214
  • +0/-0
mary

I have tried that
but from my knowledge if the default setting of "show only last 30 days" is overpassed the phone will not take into account older emails

And this is a "user side" setting (not all users will do it, and definitely users which don't care will take no action)

looking again in what mmcarn posted  I have seen a parallel discussion in SME 7 forum

http://forums.contribs.org/index.php/topic,47275.0.html

where someone pointed that files are marked with an T at the end (which is true)
I've seen this also but I found not trusted info on dovecot site

If this is true the deleting script should be like this

Code: [Select]
find /home/e-smith/files/users/*/Maildir/ -type f -name "*T" -mtime +10 -delete
if everybody's life around you is better, probably yours will be better
just try to improve their life

Offline purvis

  • ****
  • 567
  • +0/-0
Code for a bash file

Code: [Select]
find  /home/e-smith/files/users/*/Maildir/ -name "1*.*.$HOSTNAME:2*T" -type f -mtime +30 -delete

http://cr.yp.to/proto/maildir.html
« Last Edit: March 12, 2013, 09:14:24 AM by purvis »

Offline purvis

  • ****
  • 567
  • +0/-0
If your going to drop $HOSTNAME in the case of a server name change.
You might want to at least go for "1*.*.*:2*T" for the file name.
That might better describe the files wanted.
Computer experience is directly proportional to the amount of files ruined. Hahaha. I have much experience.

Offline Stefano

  • *
  • 10,836
  • +2/-0
I found this note here in the contribs forum:
http://forums.contribs.org/index.php/topic,47275.msg233222.html#msg233222

And some notes about adding plugins to dovecot to delete expired messages, but only starting with dovecot v1.1 (or 1.2):
http://wiki1.dovecot.org/Plugins/Expire

And several mentions of 'doveadm' (from dovecot v2.x):
http://wiki2.dovecot.org/Tools/Doveadm/Expunge

dovecot --version returns 1.0.7 on my SME 8 server


IMVHO, we should move to dovecot 2, starting from this work:
https://wikit.firewall-services.com/doku.php?id=smedev:dovecot

mmccarn: please fill a new feature request in bugzilla, thank you

Offline mmccarn

  • *
  • 2,626
  • +10/-0
mmccarn: please fill a new feature request in bugzilla, thank you

http://bugs.contribs.org/show_bug.cgi?id=7480

Offline janet

  • ****
  • 4,812
  • +0/-0
larieu

Quote
I have tried that but from my knowledge if the default setting of "show only last 30 days" is overpassed the phone will not take into account older emails
And this is a "user side" setting (not all users will do it, and definitely users which don't care will take no action)

This is nothing to do with how many messages to display. This relates to the purging of messages after deletion.
ie
In iPhone parlance, "how many days after a message is deleted before the message is removed (purged) from the nominated folder".

I edited my original post with more info re where to configure this on iPhones (models 3 & 5 which I have), maybe read it again.
"Settings, Mail, select account, Advanced, Deleted Messages - Remove (or similar), choose Never, One day, One week, One month,
Remember to save when exiting (select Done I think)."


Users who do not care to do it will reach their quota and then when they complain, tell them to change the settings to purge the deleted messages after say, one day.
It's a simple setting change that takes under 1 minute to do !

How you resolve your problem is your choice.
I was just correcting your statement that there was no apparent place on mobile phones to set the purge time, well there is, at least on iPhones.
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline larieu

  • ****
  • 214
  • +0/-0
janet

https://www.saratogahosting.com/hd/kb/article/email-accounts-and-forwarders/email-on-mobile-phones/iphone-remove-messages-from-server

in IMAP environment it seems that your statement is not correct
I found lots of iPhone users with overquota just because of "deleted emails"
I have set up personally three of them to delete after 3 days - no action on IMAP

and this will solve only part of problem
I have users which use android or bb or windows phones or even old type of phones... - this ask for server implementation not user side
if everybody's life around you is better, probably yours will be better
just try to improve their life

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Would it be useful to adapt the 'action' script that deletes old emails from the .junkmail folder based on a db entry?
/etc/e-smith/events/actions/purge-junkmail-folders

Yes, I think that would be a good idea. But it will only be done if somebody creates a bug in the bug tracker.

http://bugs.contribs.org/

Offline larieu

  • ****
  • 214
  • +0/-0
if everybody's life around you is better, probably yours will be better
just try to improve their life