diff --git a/lib/mail_catcher.rb b/lib/mail_catcher.rb index cf95c0f..0e665b6 100644 --- a/lib/mail_catcher.rb +++ b/lib/mail_catcher.rb @@ -80,6 +80,7 @@ module MailCatcher extend self :daemon => !windows?, :browse => false, :quit => true, + :sqlite_db => ':memory:', } def options @@ -120,6 +121,10 @@ module MailCatcher extend self options[:quit] = false end + parser.on("--sqlite-db PATH", "Set the path to the sqlite database, default in-memory only") do |db| + options[:sqlite_db] = db + end + if mac? parser.on("--[no-]growl") do |growl| puts "Growl is no longer supported" diff --git a/lib/mail_catcher/mail.rb b/lib/mail_catcher/mail.rb index a163c0b..c078222 100644 --- a/lib/mail_catcher/mail.rb +++ b/lib/mail_catcher/mail.rb @@ -6,9 +6,9 @@ require "sqlite3" module MailCatcher::Mail extend self def db @__db ||= begin - SQLite3::Database.new(":memory:", :type_translation => true).tap do |db| + SQLite3::Database.new(MailCatcher.options[:sqlite_db], :type_translation => true).tap do |db| db.execute(<<-SQL) - CREATE TABLE message ( + CREATE TABLE IF NOT EXISTS message ( id INTEGER PRIMARY KEY ASC, sender TEXT, recipients TEXT, @@ -20,7 +20,7 @@ module MailCatcher::Mail extend self ) SQL db.execute(<<-SQL) - CREATE TABLE message_part ( + CREATE TABLE IF NOT EXISTS message_part ( id INTEGER PRIMARY KEY ASC, message_id INTEGER NOT NULL, cid TEXT,