mirror of
https://github.com/moparisthebest/mailcatcher
synced 2024-12-21 23:08:54 -05:00
Add --delete-older-than to delete messages older than a time modifier every time a mail is recieved
This commit is contained in:
parent
d42f2bf11d
commit
93dd5d1758
@ -81,6 +81,7 @@ module MailCatcher extend self
|
||||
:browse => false,
|
||||
:quit => true,
|
||||
:sqlite_db => ':memory:',
|
||||
:delete_older_than => nil,
|
||||
}
|
||||
|
||||
def options
|
||||
@ -125,6 +126,10 @@ module MailCatcher extend self
|
||||
options[:sqlite_db] = db
|
||||
end
|
||||
|
||||
parser.on("--delete-older-than TIME_MODIFIER", "On mail receipt, delete all mail older than this, examples: '-5 minutes', '-2 days'") do |db|
|
||||
options[:delete_older_than] = db
|
||||
end
|
||||
|
||||
if mac?
|
||||
parser.on("--[no-]growl") do |growl|
|
||||
puts "Growl is no longer supported"
|
||||
|
@ -57,6 +57,9 @@ module MailCatcher::Mail extend self
|
||||
EventMachine.next_tick do
|
||||
message = MailCatcher::Mail.message message_id
|
||||
MailCatcher::Events::MessageAdded.push message
|
||||
if MailCatcher.options[:delete_older_than]
|
||||
MailCatcher::Mail.delete_messages_older_than!(MailCatcher.options[:delete_older_than])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -159,4 +162,11 @@ module MailCatcher::Mail extend self
|
||||
@delete_messages_query.execute(message_id) and
|
||||
@delete_message_parts_query.execute(message_id)
|
||||
end
|
||||
|
||||
def delete_messages_older_than!(modifier)
|
||||
@delete_messages_older_than_query ||= db.prepare "DELETE FROM message WHERE created_at < datetime('now', ?)"
|
||||
@delete_message_parts_older_than_query ||= db.prepare "DELETE FROM message_part WHERE created_at < datetime('now', ?)"
|
||||
@delete_messages_older_than_query.execute(modifier) and
|
||||
@delete_message_parts_older_than_query.execute(modifier)
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in New Issue
Block a user