Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: "Edward Z. Yang" <ezyang@MIT.EDU>
To: sup-devel <sup-devel@rubyforge.org>,
	"damien.leone" <damien.leone@fensalir.fr>
Subject: Re: [sup-devel] [PATCH] Implement moving message between Maildir sources based on label.
Date: Wed, 22 Aug 2012 01:54:15 -0400	[thread overview]
Message-ID: <1345614564-sup-5523@javelin> (raw)
In-Reply-To: <1345614331-17294-1-git-send-email-ezyang@mit.edu>

Usage instructions:

In config.yaml, you need to add a new option :maildir_labels:

    :maildir_labels:
      :stanford: [[:inbox, 4], [null, 6]]

Maildir labels is a dictionary of "accounts" to lists of precedences.
Read it as follows:

    For messages in source 4 or source 6 (consult sources.yaml),
    if the message has the :inbox tag, move it to source 4, otherwise
    move it to source 6.

So in this case, 6 would be some sort of Archive folder, and 4 would be INBOX.
If you want "export-only" folders, just tack them on after the null entry;
the labels are checked *in order*.  Multiple accounts are supported, but
these should be disjoint sets of sources.

This will automatically start working for any new mail you change the labels of.
In order to apply this to old mail, you need to run sup-sync-back-maildir.
OfflineIMAP will shit its pants [1] if you move too much mail, so I recommend
holding on until I implement the companion patch for OfflineIMAP if you have
a lot of mail.

Edward

[1] Namely, it will reupload every single article of mail, and if you get
unlucky and "Archive" is sorted before "INBOX", it will probably run you out
of quota too.  If you arrange to delete everything from INBOX first, and then
sync Archive, it will probably just spend a lot of time uploading.

Excerpts from Edward Z. Yang's message of Wed Aug 22 01:45:31 -0400 2012:
> From: "Edward Z. Yang" <ezyang@mit.edu>
> 
> Signed-off-by: Edward Z. Yang <ezyang@mit.edu>
> ---
>  lib/sup/maildir.rb | 28 ++++++++++++++++++++++------
>  lib/sup/message.rb |  9 +++++++--
>  2 files changed, 29 insertions(+), 8 deletions(-)
> 
> diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb
> index 95305c2..ff8da23 100644
> --- a/lib/sup/maildir.rb
> +++ b/lib/sup/maildir.rb
> @@ -77,8 +77,17 @@ class Maildir < Source
>    end
>  
>    def sync_back id, labels
> +    new_source = @id
> +    $config[:maildir_labels].each do |k,v|
> +      v.each do |lbl,i|
> +        if lbl.nil? or labels.member? lbl
> +          new_source = i
> +          break
> +        end
> +      end if v.any? { |lbl,i| i == @id }
> +    end if $config[:maildir_labels]
>      flags = maildir_reconcile_flags id, labels
> -    maildir_mark_file id, flags
> +    maildir_move_file id, new_source, flags
>    end
>  
>    def raw_header id
> @@ -221,24 +230,31 @@ private
>        new_flags.to_a.sort.join
>    end
>  
> -  def maildir_mark_file orig_path, flags
> +  def maildir_move_file orig_path, new_source_id, flags
>      @mutex.synchronize do
>        new_base = (flags.include?("S")) ? "cur" : "new"
>        md_base, md_ver, md_flags = maildir_data orig_path
>  
> -      return if md_flags == flags
> +      return if md_flags == flags and new_source_id == @id
> +
> +      new_source = SourceManager[new_source_id]
>  
>        new_loc = File.join new_base, "#{md_base}:#{md_ver},#{flags}"
>        orig_path = File.join @dir, orig_path
> -      new_path  = File.join @dir, new_loc
> +      new_path  = File.join new_source.file_path, new_loc
>        tmp_path  = File.join @dir, "tmp", "#{md_base}:#{md_ver},#{flags}"
>  
>        File.link orig_path, tmp_path
>        File.unlink orig_path
> -      File.link tmp_path, new_path
> +      begin
> +        File.link tmp_path, new_path
> +      rescue SystemCallError
> +        File.unlink new_path # XXX kinda unsafe eh
> +        File.link tmp_path, new_path
> +      end
>        File.unlink tmp_path
>  
> -      new_loc
> +      [new_source, new_loc]
>      end
>    end
>  end
> diff --git a/lib/sup/message.rb b/lib/sup/message.rb
> index 3eeea66..d6016df 100644
> --- a/lib/sup/message.rb
> +++ b/lib/sup/message.rb
> @@ -726,8 +726,13 @@ class Location
>    end
>  
>    def sync_back labels
> -    new_info = source.sync_back(@info, labels) if source.respond_to? :sync_back
> -    @info = new_info if new_info
> +    pair = source.sync_back(@info, labels) if source.respond_to? :sync_back
> +    if pair
> +      new_source, new_info = pair
> +      @source = new_source if new_source
> +      @info = new_info if new_info
> +    end
> +    pair
>    end
>  
>    ## much faster than raw_message
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


  reply	other threads:[~2012-08-22  5:54 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-21 14:35 [sup-devel] Maildir synchronizing other labels Edward Z. Yang
2012-08-22  5:45 ` [sup-devel] [PATCH] Implement moving message between Maildir sources based on label Edward Z. Yang
2012-08-22  5:54   ` Edward Z. Yang [this message]
2012-08-22 20:09     ` Edward Z. Yang
2012-08-23 14:40       ` Edward Z. Yang
2012-08-23 14:52         ` Alvaro Herrera
2012-08-23 15:28           ` Edward Z. Yang
2012-08-23 18:20           ` Edward Z. Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1345614564-sup-5523@javelin \
    --to=ezyang@mit.edu \
    --cc=damien.leone@fensalir.fr \
    --cc=sup-devel@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox