From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by 10.58.247.3 with SMTP id ya3csp623037vec; Tue, 21 Aug 2012 22:52:55 -0700 (PDT) Received: by 10.50.87.164 with SMTP id az4mr901354igb.43.1345614775056; Tue, 21 Aug 2012 22:52:55 -0700 (PDT) Return-Path: Received: from rubyforge.org (50-56-192-79.static.cloud-ips.com. [50.56.192.79]) by mx.google.com with ESMTP id mj1si5342503igc.15.2012.08.21.22.52.54; Tue, 21 Aug 2012 22:52:55 -0700 (PDT) Received-SPF: pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 50.56.192.79 as permitted sender) client-ip=50.56.192.79; Authentication-Results: mx.google.com; spf=pass (google.com: domain of sup-devel-bounces@rubyforge.org designates 50.56.192.79 as permitted sender) smtp.mail=sup-devel-bounces@rubyforge.org Received: from localhost.localdomain (localhost [127.0.0.1]) by rubyforge.org (Postfix) with ESMTP id 5E9992E07A; Wed, 22 Aug 2012 05:52:54 +0000 (UTC) Received: from dmz-mailsec-scanner-5.mit.edu (DMZ-MAILSEC-SCANNER-5.MIT.EDU [18.7.68.34]) by rubyforge.org (Postfix) with ESMTP id 23C602E05F for ; Wed, 22 Aug 2012 05:45:42 +0000 (UTC) X-AuditID: 12074422-b7f1f6d00000090b-48-50347206ab1c Received: from mailhub-auth-3.mit.edu ( [18.9.21.43]) by dmz-mailsec-scanner-5.mit.edu (Symantec Messaging Gateway) with SMTP id C8.30.02315.60274305; Wed, 22 Aug 2012 01:45:42 -0400 (EDT) Received: from outgoing.mit.edu (OUTGOING-AUTH.MIT.EDU [18.7.22.103]) by mailhub-auth-3.mit.edu (8.13.8/8.9.2) with ESMTP id q7M5jc7N004274; Wed, 22 Aug 2012 01:45:41 -0400 Received: from localhost (c-67-186-133-183.hsd1.ma.comcast.net [67.186.133.183]) (authenticated bits=0) (User authenticated as ezyang@ATHENA.MIT.EDU) by outgoing.mit.edu (8.13.6/8.12.4) with ESMTP id q7M5jZba010282; Wed, 22 Aug 2012 01:45:36 -0400 (EDT) From: "Edward Z. Yang" To: sup-devel@rubyforge.org, damien.leone@fensalir.fr Date: Wed, 22 Aug 2012 01:45:31 -0400 Message-Id: <1345614331-17294-1-git-send-email-ezyang@mit.edu> X-Mailer: git-send-email 1.7.11.3 In-Reply-To: <1345559230-sup-5105@javelin> References: <1345559230-sup-5105@javelin> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrNIsWRmVeSWpSXmKPExsUixCmqrctWZBJgsOKhoMWr831MFo+n72F3 YPKY9mslk8e+fROZA5iiuGxSUnMyy1KL9O0SuDLWffYtaBKteHlgMmsD4yH+LkZODgkBE4nW SRPZIWwxiQv31rN1MXJxCAnsY5R49WUKO4SzgVHi5Z2vjBBOD5NEz+eTYC1sAuoSj449ZQWx RQRMJeYt2s4IYjMLqEpcfn6NGcQWFgiUaD+6H6yeBSje9O4cWD2vgJ3EzqkPWSFWK0r8+L4G qJ6Dg1NAS2LWLHeQsJCApsTahZ/YJjDyLWBkWMUom5JbpZubmJlTnJqsW5ycmJeXWqRrqpeb WaKXmlK6iREULuwuSjsYfx5UOsQowMGoxMN7y8MkQIg1say4MvcQoyQHk5IoL1chUIgvKT+l MiOxOCO+qDQntfgQowQHs5IIb0UOUI43JbGyKrUoHyYlzcGiJM57LeWmv5BAemJJanZqakFq EUxWhoNDSYI3BmSoYFFqempFWmZOCUKaiYMTZDgP0HAlkBre4oLE3OLMdIj8KUZdjpezTt1l FGLJy89LlRLnrQApEgApyijNg5sDi/NXjOJAbwnz5oNU8QBTBNykV0BLmICWqF01BllSkoiQ kmpgjBDZOftIWOwq/mTTyTJbprLYt1Zuvq330+XGy3597eazBbPO85+Z0TyJU6Fjb1WxXk6/ 94wfBx73LJef6PFxDfPC5fYpVg8MH+y2m87cezcqqTEnI+uOtsbsSMuW3MS0BB7/HXMf3JE2 LT71eMefC1Vh2ZcXcC4/PKlsWtFs+R0tMuGPwtmNlViKMxINtZiLihMBLpE9q84CAAA= Subject: [sup-devel] [PATCH] Implement moving message between Maildir sources based on label. X-BeenThere: sup-devel@rubyforge.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: Sup developer discussion List-Id: Sup developer discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: sup-devel-bounces@rubyforge.org Errors-To: sup-devel-bounces@rubyforge.org From: "Edward Z. Yang" Signed-off-by: Edward Z. Yang --- 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 -- 1.7.11.3 _______________________________________________ Sup-devel mailing list Sup-devel@rubyforge.org http://rubyforge.org/mailman/listinfo/sup-devel