Clearing Spam Folders

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Clearing Spam Folders

Justin's Mailing Lists
Hi there.

I am new to the world of postfix. I have managed to successfully implement Postfix etc using workaround.org's excellent guide.

My current item on the wish list is how to sweep items from the users Spam folders after a defined number of days.

I have located this script from http://moze.koze.net/?p=161

#!/bin/bash

find /var/vmail -type d | sed ’s/ /\\ /g’ | grep “Maildir/.Spam/” |
while read line
do
find ${line}new/ -mtime +365 2>/dev/null -exec rm {} \;
find ${line}cur/ -mtime +365 2>/dev/null -exec rm {} \;

done

My guess as to what this does is the following

1. Find any occurances of .Spam directory under /var/vmail

2. for each .Spam directory found, locate and delete any items found in new and cur directories over 365 days old.

Am I correct here?

If so what do I do with this script and how do I use it in a weekly cron job?

Many thanks for your help here.

Regards

Justin

Reply | Threaded
Open this post in threaded view
|

Re: Clearing Spam Folders

Barney Desmond
2009/8/24 Justin C. Le Grice <[hidden email]>:
> I am new to the world of postfix. I have managed to successfully implement
> Postfix etc using workaround.org's excellent guide.
>
> My current item on the wish list is how to sweep items from the users Spam
> folders after a defined number of days.

This is the Postfix list, Postfix is only an MTA. It does not deal
with serving mailboxes. That said...

> I have located this script from http://moze.koze.net/?p=161
>
<snip>
> My guess as to what this does is the following

You really don't want to be guessing here - it could wipe out your
system for all you know. The script should have documentation. If not,
you need to learn up on shell scripting.

> 1. Find any occurances of .Spam directory under /var/vmail
>
> 2. for each .Spam directory found, locate and delete any items found in new
> and cur directories over 365 days old.
>
> Am I correct here?

That sounds about right.

> If so what do I do with this script

You run it, however you want.

> and how do I use it in a weekly cron
> job?

Put it in a weekly cronjob.


I don't mean to come off as rude, but these aren't really good
questions, relevant or otherwise.
Reply | Threaded
Open this post in threaded view
|

Re: (OT!) Clearing Spam Folders

Justin's Mailing Lists
Barney Desmond wrote:
2009/8/24 Justin C. Le Grice [hidden email]:
  
I am new to the world of postfix. I have managed to successfully implement
Postfix etc using workaround.org's excellent guide.

My current item on the wish list is how to sweep items from the users Spam
folders after a defined number of days.
    

This is the Postfix list, Postfix is only an MTA. It does not deal
with serving mailboxes. That said...

  
I have located this script from http://moze.koze.net/?p=161

    
<snip>
  
My guess as to what this does is the following
    

You really don't want to be guessing here - it could wipe out your
system for all you know. The script should have documentation. If not,
you need to learn up on shell scripting.

  
1. Find any occurances of .Spam directory under /var/vmail

2. for each .Spam directory found, locate and delete any items found in new
and cur directories over 365 days old.

Am I correct here?
    

That sounds about right.

  
If so what do I do with this script
    

You run it, however you want.

  
and how do I use it in a weekly cron
job?
    

Put it in a weekly cronjob.


I don't mean to come off as rude, but these aren't really good
questions, relevant or otherwise.
  
Gee Barney that was really friendly, NOT!

If you had read what I was asking you should have worked out that I am looking for a solution for a particular issue I wish to resolve. I was trying to understand how this one worked. I have not implemented it because I was not 100% how it worked, nor how to tweak it to suit my needs.

As I also said I am new to Postfix, and also Linux so am gingerly feeling my way through setting up this mail server. I posed my question here because I was sure the friendly (now I'm not so sure) folks here would have come across this particular problem and would have a solution.

Cheers
Reply | Threaded
Open this post in threaded view
|

Re: (OT!) Clearing Spam Folders

Sahil Tandon
On Tue, 25 Aug 2009, Justin C. Le Grice wrote:

> Barney Desmond wrote:

[...]

>>> and how do I use it in a weekly cron
>>> job?
>>>    
>>
>> Put it in a weekly cronjob.
>>
>> I don't mean to come off as rude, but these aren't really good
>> questions, relevant or otherwise.
>>  
> Gee Barney that was really friendly, NOT!

He was being gentle; your ire is misplaced.

> If you had read what I was asking you should have worked out that I am  
> looking for a solution for a particular issue I wish to resolve. I was  
> trying to understand how this one worked. I have not implemented it  
> because I was not 100% how it worked, nor how to tweak it to suit my
> needs.
>
> As I also said I am new to Postfix, and also Linux so am gingerly  
> feeling my way through setting up this mail server. I posed my question  
> here because I was sure the friendly (now I'm not so sure) folks here  
> would have come across this particular problem and would have a solution.

This is not the right mailing list for your general Linux/UNIX questions.
See: http://www.catb.org/~esr/faqs/smart-questions.html, especially the
section titled "Choose your forum carefully".

--
Sahil Tandon <[hidden email]>
Reply | Threaded
Open this post in threaded view
|

Re: (OT!) Clearing Spam Folders

Michael Orlitzky-2
In reply to this post by Justin's Mailing Lists
Justin C. Le Grice wrote:

> Barney Desmond wrote:
>> 2009/8/24 Justin C. Le Grice <[hidden email]>:
>>  
>>> I am new to the world of postfix. I have managed to successfully implement
>>> Postfix etc using workaround.org's excellent guide.
>>>
>>> My current item on the wish list is how to sweep items from the users Spam
>>> folders after a defined number of days.
>>>    
>>
>> This is the Postfix list, Postfix is only an MTA. It does not deal
>> with serving mailboxes. That said...
>>
>>  
>>> I have located this script from http://moze.koze.net/?p=161
>>>
>>>    
>> <snip>
>>  
>>> My guess as to what this does is the following
>>>    
>>
>> You really don't want to be guessing here - it could wipe out your
>> system for all you know. The script should have documentation. If not,
>> you need to learn up on shell scripting.
>>
>>  
>>> 1. Find any occurances of .Spam directory under /var/vmail
>>>
>>> 2. for each .Spam directory found, locate and delete any items found in new
>>> and cur directories over 365 days old.
>>>
>>> Am I correct here?
>>>    
>>
>> That sounds about right.
>>
>>  
>>> If so what do I do with this script
>>>    
>>
>> You run it, however you want.
>>
>>  
>>> and how do I use it in a weekly cron
>>> job?
>>>    
>>
>> Put it in a weekly cronjob.
>>
>>
>> I don't mean to come off as rude, but these aren't really good
>> questions, relevant or otherwise.
>>  
> Gee Barney that was really friendly, NOT!
>
> If you had read what I was asking you should have worked out that I am
> looking for a solution for a particular issue I wish to resolve. I was
> trying to understand how this one worked. I have not implemented it
> because I was not 100% how it worked, nor how to tweak it to suit my needs.
>
> As I also said I am new to Postfix, and also Linux so am gingerly
> feeling my way through setting up this mail server. I posed my question
> here because I was sure the friendly (now I'm not so sure) folks here
> would have come across this particular problem and would have a solution.
>
> Cheers

Ideally, the script would find all subdirectories of /var/vmail
containing the string "Maildir/.Spam/" and then delete the messages in
those directories which are older than 365 days. But it's buggy.

First of all, if you copy-and-pasted the code exactly, the apostrophes
around the sed command most likely did not come through, nor did the
quotes around grep's argument. That page uses HTML entities for angled
quotes, rather than plain ASCII ones. Fortunately, sed and grep will
crash, rather than, say, passing all of your files to the "rm" command.

Second, it's grepping for a path containing "Maildir/.Spam/" and then
trying to delete within that path. Try running "find" somewhere on your
machine. Do the directories end with slashes? Not here, they don't. So,
the script doesn't even empty the .Spam folder. It /almost/ empties the
subdirectories of the .Spam folder, but the author is missing two front
slashes in his find commands. For example, given the following directory
structure,

   $ ls /var/vmail/example.com/user/Maildir/.Spam/
   drwxr-xr-x 2 mjo mjo 4.0K 2009-08-25 00:32 old-spam
   -rw-r--r-- 1 mjo mjo    0 2009-08-25 00:32 test.msg

The script will try to execute the (truncated) commands:

   find /var/vmail/example.com/user/Maildir/.Spam/old-spamnew/ ...
   find /var/vmail/example.com/user/Maildir/.Spam/old-spamcur/ ...

which are clearly incorrect.

Third, if you followed the workaround.org tutorial, you don't even have
.Spam folders, you have .spam folders, and the case of the 's' matters.

You don't want to run a script like this (as root!) without knowing what
it does. One misplaced front slash or period could cause you to erase
the entire filesystem. You can cause similar damage with cron if you
just follow some stranger's advice without making sure you understand
what you're doing.

Finally, the workaround.org tutorial involves Dovecot, which already has
a plugin to do exactly what you want:

   http://wiki.dovecot.org/Plugins/Expire

The setup is a little painful, but it's The Right Way To Do It. Help can
be found on the Dovecot mailing list. And please, forget everything you
read on that script's website.
Reply | Threaded
Open this post in threaded view
|

Re: (OT!) Clearing Spam Folders

Justin's Mailing Lists
Michael Orlitzky wrote:

> Justin C. Le Grice wrote:
>> Barney Desmond wrote:
>>> 2009/8/24 Justin C. Le Grice <[hidden email]>:
>>>  
>
> Ideally, the script would find all subdirectories of /var/vmail
> containing the string "Maildir/.Spam/" and then delete the messages in
> those directories which are older than 365 days. But it's buggy.
>
> First of all, if you copy-and-pasted the code exactly, the apostrophes
> around the sed command most likely did not come through, nor did the
> quotes around grep's argument. That page uses HTML entities for angled
> quotes, rather than plain ASCII ones. Fortunately, sed and grep will
> crash, rather than, say, passing all of your files to the "rm" command.
>
> Second, it's grepping for a path containing "Maildir/.Spam/" and then
> trying to delete within that path. Try running "find" somewhere on
> your machine. Do the directories end with slashes? Not here, they
> don't. So, the script doesn't even empty the .Spam folder. It /almost/
> empties the subdirectories of the .Spam folder, but the author is
> missing two front slashes in his find commands. For example, given the
> following directory structure,
>
>   $ ls /var/vmail/example.com/user/Maildir/.Spam/
>   drwxr-xr-x 2 mjo mjo 4.0K 2009-08-25 00:32 old-spam
>   -rw-r--r-- 1 mjo mjo    0 2009-08-25 00:32 test.msg
>
> The script will try to execute the (truncated) commands:
>
>   find /var/vmail/example.com/user/Maildir/.Spam/old-spamnew/ ...
>   find /var/vmail/example.com/user/Maildir/.Spam/old-spamcur/ ...
>
> which are clearly incorrect.
>
> Third, if you followed the workaround.org tutorial, you don't even
> have .Spam folders, you have .spam folders, and the case of the 's'
> matters.
>
> You don't want to run a script like this (as root!) without knowing
> what it does. One misplaced front slash or period could cause you to
> erase the entire filesystem. You can cause similar damage with cron if
> you just follow some stranger's advice without making sure you
> understand what you're doing.
>
> Finally, the workaround.org tutorial involves Dovecot, which already
> has a plugin to do exactly what you want:
>
>   http://wiki.dovecot.org/Plugins/Expire
>
> The setup is a little painful, but it's The Right Way To Do It. Help
> can be found on the Dovecot mailing list. And please, forget
> everything you read on that script's website.

Thank you very much Michael.

This is most helpful and to paraphrase you "Use the right tool for the
job". Which was why I posted the message initially.

Now off to find Dovecot mailing list join instructions and read about
Expire.

Cheers.