Skip to content

Commit

Permalink
Merge pull request #57 from jasonwbarnett/master
Browse files Browse the repository at this point in the history
Added two methods for labels and fixed a bug
  • Loading branch information
myobie committed Mar 28, 2014
2 parents 9985363 + 48e0520 commit dfbf878
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions lib/gmail.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ def inbox
in_label('inbox')
end

def destroy_label(name)
imap.delete(name)
end

def rename_label(oldname, newname)
imap.rename(oldname, newname)
end

def create_label(name)
imap.create(name)
end
Expand All @@ -48,8 +56,11 @@ def mailbox_list

# List the available labels
def labels
mailbox_list.inject([]) { |labels,label|
label[:name].each_line { |l| labels << l }; labels }
mailbox_list.inject([]) do |labels,label|
labels << label[:name] unless label.attr.include?(:Noselect)

labels
end
end

# gmail.label(name)
Expand All @@ -67,13 +78,13 @@ def find_label_by_attribute(attribute)

###########################
# MAKING EMAILS
#
#
# gmail.generate_message do
# ...inside Mail context...
# end
#
#
# gmail.deliver do ... end
#
#
# mail = Mail.new...
# gmail.deliver!(mail)
###########################
Expand Down Expand Up @@ -113,12 +124,12 @@ def logout
@logged_in = false if res && res.name == 'OK'
end
end

# Shutdown socket and disconnect
def disconnect
logout if logged_in?
@imap.disconnect unless @imap.disconnected?
end
end

def in_mailbox(mailbox, &block)
if block_given?
Expand Down Expand Up @@ -147,7 +158,7 @@ def in_mailbox(mailbox, &block)
def inspect
"#<Gmail:#{'0x%x' % (object_id << 1)} (#{meta.username}) #{'dis' if !logged_in?}connected>"
end

# Accessor for @imap, but ensures that it's logged in first.
def imap
unless logged_in?
Expand Down

0 comments on commit dfbf878

Please sign in to comment.