commit 96113d0a62b2deb613cd1d54d59fdc2ad534acb7
parent 353dc12c827d32fe225a49625ac1194e27e7ee29
Author: Eric Weikl <eric.weikl@gmx.net>
Date: Sun, 8 Sep 2013 15:03:26 +0200
Individual sync_back configuration option
It's now possible to (de)activate Maildir sync back per Maildir source, using
the sync_back source configuration flag. For backwards compatibility with the
previous implementation, the global :sync_back_to_maildir still exists and
must be set to allow sync back. Additionally, sync back is _active_ by
default per source, i.e. unless sync_back is explicitly set to false, sync
back will occur.
Fixes #141
Diffstat:
5 files changed, 26 insertions(+), 6 deletions(-)
diff --git a/bin/sup-add b/bin/sup-add
@@ -30,6 +30,7 @@ Options are:
EOS
opt :archive, "Automatically archive all new messages from these sources."
opt :unusual, "Do not automatically poll these sources for new messages."
+ opt :sync_back, "Synchronize status flags back into messages, defaults to true (Maildir sources only).", :default => true
opt :labels, "A comma-separated set of labels to apply to all messages from this source", :type => String
opt :force_new, "Create a new account for this source, even if one already exists."
opt :force_account, "Reuse previously defined account user@hostname.", :type => String
@@ -99,7 +100,7 @@ begin
source =
case parsed_uri.scheme
when "maildir"
- Redwood::Maildir.new uri, !$opts[:unusual], $opts[:archive], nil, labels
+ Redwood::Maildir.new uri, !$opts[:unusual], $opts[:archive], $opts[:sync_back], nil, labels
when "mbox"
Redwood::MBox.new uri, !$opts[:unusual], $opts[:archive], nil, labels
when nil
diff --git a/bin/sup-config b/bin/sup-config
@@ -88,6 +88,8 @@ def add_source
usual = axe_yes "Does this source ever receive new messages?", "y"
archive = usual ? axe_yes("Should new messages be automatically archived? (I.e. not appear in your inbox, though still be accessible via search.)") : false
+ sync_back = (type == :maildir) ? axe_yes("Should the original Maildir messages be modified to reflect changes like read status, starred messages, etc.?", "y") : false
+
labels_str = axe("Enter any labels to be automatically added to all messages from this source, separated by spaces (or 'none')", default_labels.join(","))
labels = if labels_str =~ /^\s*none\s*$/i
@@ -99,6 +101,7 @@ def add_source
cmd = build_cmd "sup-add"
cmd += " --unusual" unless usual
cmd += " --archive" if archive
+ cmd += " --no-sync-back" unless sync_back
cmd += " --labels=#{labels.join(',')}" if labels && !labels.empty?
cmd += " #{uri}"
diff --git a/bin/sup-sync-back-maildir b/bin/sup-sync-back-maildir
@@ -31,7 +31,8 @@ Usage:
sup-sync-back-maildir [options] <source>*
where <source>* is source URIs. If no source is given, the default
-behavior is to sync back all Maildir sources.
+behavior is to sync back all Maildir sources that have not disabled
+sync back using the configuration parameter sync_back = false.
Options include:
EOS
@@ -60,12 +61,15 @@ begin
sources = ARGV.map do |uri|
s = Redwood::SourceManager.source_for(uri) or die "unknown source: #{uri}. Did you add it with sup-add first?"
s.is_a?(Redwood::Maildir) or die "#{uri} is not a Maildir source."
+ s.sync_back_enabled? or die "#{uri} has disabled sync back - check your configuration."
s
end unless opts[:list_sources]
## Otherwise, check all sources in sources.yaml
if sources.empty? or opts[:list_sources] == true
- sources = Redwood::SourceManager.usual_sources.select { |s| s.is_a? Redwood::Maildir }
+ sources = Redwood::SourceManager.usual_sources.select do |s|
+ s.is_a? Redwood::Maildir and s.sync_back_enabled?
+ end
end
if opts[:list_sources] == true
diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb
@@ -8,8 +8,8 @@ class Maildir < Source
MYHOSTNAME = Socket.gethostname
## remind me never to use inheritance again.
- yaml_properties :uri, :usual, :archived, :id, :labels
- def initialize uri, usual=true, archived=false, id=nil, labels=[]
+ yaml_properties :uri, :usual, :archived, :sync_back, :id, :labels
+ def initialize uri, usual=true, archived=false, sync_back=true, id=nil, labels=[]
super uri, usual, archived, id
@expanded_uri = Source.expand_filesystem_uri(uri)
uri = URI(@expanded_uri)
@@ -18,6 +18,10 @@ class Maildir < Source
raise ArgumentError, "maildir URI cannot have a host: #{uri.host}" if uri.host
raise ArgumentError, "maildir URI must have a path component" unless uri.path
+ @sync_back = sync_back
+ # sync by default if not specified
+ @sync_back = true if @sync_back.nil?
+
@dir = uri.path
@labels = Set.new(labels || [])
@mutex = Mutex.new
@@ -32,6 +36,10 @@ class Maildir < Source
[:draft, :starred, :forwarded, :replied, :unread, :deleted]
end
+ def sync_back_enabled?
+ @sync_back
+ end
+
def store_message date, from_email, &block
stored = false
new_fn = new_maildir_basefn + ':2,S'
diff --git a/lib/sup/message.rb b/lib/sup/message.rb
@@ -732,7 +732,7 @@ class Location
def sync_back labels, message
synced = false
- return synced unless $config[:sync_back_to_maildir] and valid? and source.respond_to? :sync_back
+ return synced unless sync_back_enabled? and valid?
source.synchronize do
new_info = source.sync_back(@info, labels)
if new_info
@@ -744,6 +744,10 @@ class Location
synced
end
+ def sync_back_enabled?
+ source.respond_to? :sync_back and $config[:sync_back_to_maildir] and source.sync_back_enabled?
+ end
+
## much faster than raw_message
def each_raw_message_line &b
source.each_raw_message_line info, &b