diff options
author | Bernie Maier <feed2imap@lists.blurk.net> | 2010-06-28 23:01:13 +1000 |
---|---|---|
committer | Lucas Nussbaum <lucas@lucas-nussbaum.net> | 2010-07-05 08:56:34 +0200 |
commit | 94dc1db641f98242496a32409e823920f4e700e9 (patch) | |
tree | e4b0852848183a9b058f13fb916f7459ef6cd2f8 /lib | |
parent | c5d45c75e5a81c9eb86821b20f42a63ffe179c96 (diff) | |
download | feed2imap-94dc1db641f98242496a32409e823920f4e700e9.tar.gz feed2imap-94dc1db641f98242496a32409e823920f4e700e9.tar.bz2 feed2imap-94dc1db641f98242496a32409e823920f4e700e9.zip |
Patch to use feed item pubDate in Maildir file names
Hi!
I've just subscribed to the list, having downloaded feed2imap a few days
ago. Since I want to just write RSS feeds to a local Maildir, this
looked like just what I needed.
Unfortunately, the release 1.0 version seems to randomise the order of
the feed items when doing the first fetch for a new feed. Looking at
maildir.rb, there is a "TODO: handle `date'" comment and it looks like
the code is just generating maildir filenames using the timestamp at
the time the items are being written into the maildir. Since all
the initial items are written at the same time, and the maildir file
name has a random element, this loses the original ordering from the
mail feed.
The solution is to use the timestamp corresponding to the pubDate
in the feed item as the initial component of the maildir file name.
Also, instead of using a random integer to force uniqueness in the
second component of the file name, I think it is better to use a
sequence number for each feed item, which will still be unique for
the feed and also preserve item order.
My patch follows (it's the first piece of Ruby code I've ever
written / modified)...
Cheers,
Bernie
Diffstat (limited to '')
-rw-r--r-- | lib/feed2imap/maildir.rb | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/lib/feed2imap/maildir.rb b/lib/feed2imap/maildir.rb index a18e5aa..76678e2 100644 --- a/lib/feed2imap/maildir.rb +++ b/lib/feed2imap/maildir.rb @@ -25,6 +25,10 @@ class MaildirAccount attr_reader :uri + def initialize + @seq_num = 0 + end + def putmail(folder, mail, date = Time::now) store_message(folder_dir(folder), date, nil) do |f| f.puts(mail) @@ -84,7 +88,6 @@ class MaildirAccount end def store_message(dir, date, info, &block) - # TODO: handle `date' guarantee_maildir(dir) @@ -93,7 +96,7 @@ class MaildirAccount timer = 30 fd = nil while timer >= 0 - new_fn = new_maildir_basefn + new_fn = new_maildir_basefn(date) tmp_path = File.join(dir, 'tmp', new_fn) new_path = File.join(dir, 'new', new_fn) begin @@ -160,11 +163,12 @@ class MaildirAccount return (colon and basename.slice(colon + 1, -1)) end - # Shamelessly taken from + # Re-written and no longer shamelessly taken from # http://gitorious.org/sup/mainline/blobs/master/lib/sup/maildir.rb - def new_maildir_basefn - Kernel::srand() - "#{Time.now.to_i.to_s}.#{$$}#{Kernel.rand(1000000)}.#{MYHOSTNAME}" + def new_maildir_basefn(date) + fn = "#{date.to_i.to_s}.#{@seq_num.to_s}.#{MYHOSTNAME}" + @seq_num = @seq_num + 1 + fn end end |