You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.



Junk Mail Purging
Seth Spitzer
for testing, use these:

NSPR_LOG_FILE=c:\purgelog.txt
NSPR_LOG_MODULES=MsgPurge:5

user_pref("mail.purge.min_delay",5); (default is 480 minutes, or 8 hours)
user_pref("mail.purge.timer_interval",1); (default is 5 minutes)

timer_interval is how often we check to see if something is ready to be purged
min_delay is, for a given folder, has it been long enough since our last purge?

let's say I had two accounts, pop and imap, both with their own junk folders, both with purge enabled.

here's how this should work:

startup

five minutes later:
  look for something to purge
  find pop junk folder, never been purged, purge it.
  set lastPurgeTime for that folder to now.
 
five minutes later:
  look for something to purge
  see that pop junk folder was purged 5 minutes ago (which is not more than 8 hours), so skip it. 
  find imap junk folder, never been purged, purge it.

five minutes
  look for something to purge
  see that pop junk folder was purged 10 minutes ago (which is not more than 8 hours), so skip it. 
  see that imap junk folder was purged 5 minutes ago (which is not more than 8 hours), so skip it. 

five minutes later:
  look for something to purge
  see that pop junk folder was purged 15 minutes ago (which is not more than 8 hours), so skip it. 
  see that imap junk folder was purged 10 minutes ago (which is not more than 8 hours), so skip it. 

...

five minutes later:
  look for something to purge
  see that pop junk folder was purged 485 minutes ago (which IS more than 8 hours), purge it.
  set lastPurgeTime for that folder to now.

five minutes later:
  look for something to purge
  see that pop junk folder was purged 5 minutes ago (which is not more than 8 hours), so skip it. 
  see that pop junk folder was purged 485 minutes ago (which IS more than 8 hours), purge it.
  set lastPurgeTime for that folder to now.

Because lastPurgeTime is stored on the folder, if you exit and restart in there, it should not matter.

(Note, without min_delay (or if min_delay is < timer_interval), you'd just keep purging the same folder over and over, and never get to the other folders.)

More info:

every mail.purge.timer_interval minutes (starting when mail accounts are loaded), looping through all accounts and

find the first server that:
  • can get incoming messages (if you can't, we don't bother, since this type of account won't show up in the JMC)
  • and is enabled to do purging
  • and has a valid junk folder that exists
  • and hasn't been purged in mail.purge.min_delay minutes.
  • and isn't busy (like if this was a pop account, and we were getting new mail)
  • and if we require authentication to open the junk folder (like on imap)
  • and we're authenticated

if we find one, we stop looking and search that folder for any messages older than the per-JMC purge interval.

on the search results, we only delete messages that are marked as junk.
we do this by checking the junkscore attribute on the msgHdr (which is stored in the .msf file)

It would have been more efficient to have done:
"search for all messages older than n days that are junk."
But we can't do it that way, because not all IMAP servers support that kind of search.
So, instead, we search for "all messages older than n days", and only delete the messages that are marked as junk.
They are marked as junk in the .msf file (msg db).

now update when that account was last purged. (this is stored on the junk mail
folder, so if the junk mail folder is shared, we do the right thing)

we only purge one account per timer firing.

if I have 5 accounts that are set up for purging,
it will take 5 timer firing to get to them all.
(the purge service can only do one at a time.)

Because the last purge time is stored on the folder, the "mail.purge.min_delay" interval should work across sessions.