lib/gmail/mailbox.rb in gmail-0.3.2 vs lib/gmail/mailbox.rb in gmail-0.3.3

- old
+ new

@@ -1,11 +1,21 @@ module Gmail class Mailbox MAILBOX_ALIASES = { - :all => ['ALL'], - :unread => ['UNSEEN'], #'UNREAD'], - :read => ['SEEN'], #'READ'] + :all => ['ALL'], + :seen => ['SEEN'], + :unseen => ['UNSEEN'], + :read => ['SEEN'], + :unread => ['UNSEEN'], + :flagged => ['FLAGGED'], + :unflagged => ['UNFLAGGED'], + :starred => ['FLAGGED'], + :unstarred => ['UNFLAGGED'], + :deleted => ['DELETED'], + :undeleted => ['UNDELETED'], + :draft => ['DRAFT'], + :undrafted => ['UNDRAFT'] } attr_reader :name def initialize(gmail, name="INBOX") @@ -30,11 +40,11 @@ # end def emails(*args, &block) args << :all if args.size == 0 if args.first.is_a?(Symbol) - search = MAILBOX_ALIASES[args.shift] + search = MAILBOX_ALIASES[args.shift].dup opts = args.first.is_a?(Hash) ? args.first : {} opts[:after] and search.concat ['SINCE', opts[:after].to_imap_date] opts[:before] and search.concat ['BEFORE', opts[:before].to_imap_date] opts[:on] and search.concat ['ON', opts[:on].to_imap_date] @@ -74,10 +84,15 @@ # gmail.mailbox("Test").count(:all, :after => Time.now-(20*24*3600)) def count(*args) emails(*args).size end + # This permanently removes messages which are marked as deleted + def expunge + @gmail.mailbox(name) { @gmail.conn.expunge } + end + # Cached messages. def messages @messages ||= {} end @@ -86,7 +101,13 @@ end def to_s name end + + MAILBOX_ALIASES.each { |mailbox| + define_method(mailbox) do |*args, &block| + emails(mailbox, *args, &block) + end + } end # Message end # Gmail