From: William Morgan Date: Wed, 19 Aug 2009 18:32:46 +0000 (-0400) Subject: have mbox, maildir and imap sources (de)serialize labels nicely X-Git-Url: https://git.cworth.org/git?p=sup;a=commitdiff_plain;h=70bcc4ed051c389e82b76dc6f57e5f009aac1e83 have mbox, maildir and imap sources (de)serialize labels nicely At output time, rather than emitting a YAML Set (which is nasty), emit an array of strings. At input time, normalize into a Set of labels. --- diff --git a/lib/sup/imap.rb b/lib/sup/imap.rb index 14acdb7..b048ba9 100644 --- a/lib/sup/imap.rb +++ b/lib/sup/imap.rb @@ -48,6 +48,7 @@ require 'set' module Redwood class IMAP < Source + include SerializeLabelsNicely SCAN_INTERVAL = 60 # seconds ## upon these errors we'll try to rereconnect a few times diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb index 80903e2..db35dad 100644 --- a/lib/sup/maildir.rb +++ b/lib/sup/maildir.rb @@ -9,6 +9,7 @@ module Redwood ## pathnames on disk. class Maildir < Source + include SerializeLabelsNicely SCAN_INTERVAL = 30 # seconds MYHOSTNAME = Socket.gethostname diff --git a/lib/sup/mbox/loader.rb b/lib/sup/mbox/loader.rb index 26177f7..0307594 100644 --- a/lib/sup/mbox/loader.rb +++ b/lib/sup/mbox/loader.rb @@ -6,6 +6,7 @@ module Redwood module MBox class Loader < Source + include SerializeLabelsNicely yaml_properties :uri, :cur_offset, :usual, :archived, :id, :labels ## uri_or_fp is horrific. need to refactor. diff --git a/lib/sup/source.rb b/lib/sup/source.rb index fb9089f..0705a75 100644 --- a/lib/sup/source.rb +++ b/lib/sup/source.rb @@ -161,6 +161,21 @@ protected end end +## if you have a @labels instance variable, include this +## to serialize them nicely as an array, rather than as a +## nasty set. +module SerializeLabelsNicely + def before_marshal # can return an object + c = clone + c.instance_eval { @labels = @labels.to_a.map { |l| l.to_s } } + c + end + + def after_unmarshal! + @labels = Set.new(@labels.map { |s| s.to_sym }) + end +end + class SourceManager include Singleton