diff --git a/README.md b/README.md index 162c9dd..cdf79aa 100644 --- a/README.md +++ b/README.md @@ -353,4 +353,4 @@ This project follows on Open Governance model. The Core Team is responsible for * Copyright (c) 2010-2014 Kriss 'nu7hatch' Kowalik * Copyright (c) 2009-2010 BehindLogic -Licensed under the MIT license. See [LICENSE](https://github.com/gmailgem/gmail/blob/master/LICENSE) for details. +Licensed under the MIT license. See [LICENSE](https://github.com/gmailgem/gmail/blob/master/LICENSE) for details.entrar diff --git a/lib/gmail/client.rb b/lib/gmail/client.rb index b1012d1..65a9e5d 100644 --- a/lib/gmail/client.rb +++ b/lib/gmail/client.rb @@ -8,6 +8,8 @@ class AuthorizationError < Net::IMAP::NoResponseError; end class DeliveryError < ArgumentError; end # Raised when given client is not registered class UnknownClient < ArgumentError; end + # Raised when email not found + class EmailNotFound < ArgumentError; end def self.clients @clients ||= {} diff --git a/lib/gmail/client/base.rb b/lib/gmail/client/base.rb index ed95e87..aac9a8c 100644 --- a/lib/gmail/client/base.rb +++ b/lib/gmail/client/base.rb @@ -184,6 +184,12 @@ def inbox mailbox("INBOX") end + # Functionality like rails #find method + def find(message_id) + message = mailbox('[Gmail]/All Mail').find(message_id: message_id).first + raise EmailNotFound, "Can't find message with ID #{message_id}" unless message + end + def mailboxes @mailboxes ||= {} end diff --git a/lib/gmail/mailbox.rb b/lib/gmail/mailbox.rb index 6db2aa2..818df8a 100644 --- a/lib/gmail/mailbox.rb +++ b/lib/gmail/mailbox.rb @@ -44,6 +44,7 @@ def fetch_uids(*args) opts[:body] and search.concat ['BODY', opts[:body]] opts[:uid] and search.concat ['UID', opts[:uid]] opts[:gm] and search.concat ['X-GM-RAW', opts[:gm]] + opts[:message_id] and search.concat ['X-GM-MSGID', opts[:message_id]] opts[:query] and search.concat opts[:query] @gmail.mailbox(name) { diff --git a/lib/gmail/message.rb b/lib/gmail/message.rb index c614039..983937e 100644 --- a/lib/gmail/message.rb +++ b/lib/gmail/message.rb @@ -125,14 +125,9 @@ def unarchive! alias_method :unspam!, :unarchive! alias_method :undelete!, :unarchive! - # Move to given box and delete from others. - # Apply a given label and optionally remove one. - # TODO: We should probably deprecate this method. It doesn't really add a lot - # of value, especially since the concept of "moving" a message from one - # label to another doesn't totally make sense in the Gmail world. def move_to(name, from = nil) add_label(name) - remove_label(from) if from + @gmail.find(message_id).remove_label(from) if from end alias_method :move, :move_to alias_method :move!, :move_to