lib/sup/message.rb in sup-0.14.1.1 vs lib/sup/message.rb in sup-0.15.0

- old
+ new

@@ -289,10 +289,36 @@ def each_raw_message_line &b location.each_raw_message_line &b end + def sync_back + @locations.map { |l| l.sync_back @labels, self }.any? do + UpdateManager.relay self, :updated, self + end + end + + def merge_labels_from_locations merge_labels + ## Get all labels from all locations + location_labels = Set.new([]) + + @locations.each do |l| + if l.valid? + location_labels = location_labels.union(l.labels?) + end + end + + ## Add to the message labels the intersection between all location + ## labels and those we want to merge + location_labels = location_labels.intersection(merge_labels.to_set) + + if not location_labels.empty? + @labels = @labels.union(location_labels) + @dirty = true + end + end + ## returns all the content from a message that will be indexed def indexable_content load_from_source! [ from && from.indexable_content, @@ -543,14 +569,22 @@ ## looks for gpg signed (but not encrypted) inline messages inside the ## message body (there is no extra header for inline GPG) or for encrypted ## (and possible signed) inline GPG messages def inline_gpg_to_chunks body, encoding_to, encoding_from lines = body.split("\n") + + # First case: Message is enclosed between + # + # -----BEGIN PGP SIGNED MESSAGE----- + # and + # -----END PGP SIGNED MESSAGE----- + # + # In some cases, END PGP SIGNED MESSAGE doesn't appear gpg = lines.between(GPG_SIGNED_START, GPG_SIGNED_END) # between does not check if GPG_END actually exists # Reference: http://permalink.gmane.org/gmane.mail.sup.devel/641 - if !gpg.empty? && !lines.index(GPG_END).nil? + if !gpg.empty? msg = RMail::Message.new msg.body = gpg.join("\n") body = body.transcode(encoding_to, encoding_from) lines = body.split("\n") @@ -558,18 +592,25 @@ startidx = lines.index(GPG_SIGNED_START) endidx = lines.index(GPG_SIG_END) before = startidx != 0 ? lines[0 .. startidx-1] : [] after = endidx ? lines[endidx+1 .. lines.size] : [] + # sig contains BEGIN PGP SIGNED MESSAGE and END PGP SIGNATURE, so + # we ditch them. sig may also contain the hash used by PGP (with a + # newline), so we also skip them + sig_start = sig[1].match(/^Hash:/) ? 3 : 1 + sig_end = sig.size-2 payload = RMail::Message.new - payload.body = sig[1, sig.size-2].join("\n") + payload.body = sig[sig_start, sig_end].join("\n") return [text_to_chunks(before, false), CryptoManager.verify(nil, msg, false), message_to_chunks(payload), text_to_chunks(after, false)].flatten.compact end + # Second case: Message is encrypted + gpg = lines.between(GPG_START, GPG_END) # between does not check if GPG_END actually exists if !gpg.empty? && !lines.index(GPG_END).nil? msg = RMail::Message.new msg.body = gpg.join("\n") @@ -702,10 +743,28 @@ def raw_message source.raw_message info end + def sync_back labels, message + synced = false + return synced unless sync_back_enabled? and valid? + source.synchronize do + new_info = source.sync_back(@info, labels) + if new_info + @info = new_info + Index.sync_message message, true + synced = true + end + end + 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 end @@ -713,9 +772,13 @@ source.load_message info end def valid? source.valid? info + end + + def labels? + source.labels? info end def == o o.source.id == source.id and o.info == info end