aboutsummaryrefslogtreecommitdiffstats
path: root/lib/puke/core.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/puke/core.rb')
-rw-r--r--lib/puke/core.rb14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/puke/core.rb b/lib/puke/core.rb
index 4cbb0d5..23fb429 100644
--- a/lib/puke/core.rb
+++ b/lib/puke/core.rb
@@ -43,12 +43,13 @@ module Puke
@gdbm.fetch("t#{tid}").split("\0")
end
- def mid?(mid)
- @gdbm["m#{mid}"]&.split("\0")&.first
+ def tid_for(mid)
+ Puke.metadata(mid)&.fetch(:tid)
end
def metadata(mid)
- tid, subject, date = @gdbm["m#{mid}"].split("\0")
+ data = @gdbm["m#{mid}"] or return
+ tid, subject, date = data.split("\0")
{ mid: mid, tid: tid.to_i, subject: subject, date: Time.rfc2822(date) }
end
@@ -64,10 +65,9 @@ module Puke
# A mutex is used here in case two threads try to store the same message
CreateMutex.synchronize {
# File.exist?(fpath) is needed here because of the mangling...
- if Puke.mid?(mid) or File.exist?(fpath)
- existing = Puke.metadata(mid)
- if (!tid || tid == existing[:tid]) && subject == existing[:subject] &&
- date == existing[:date]
+ if existing = Puke.metadata(mid) or File.exist?(fpath)
+ if existing && (!tid || tid == existing[:tid]) &&
+ subject == existing[:subject] && date == existing[:date]
raise "duplicate message"
else
# TODO: Oops, how to deal with this case?