Skip to content

Instantly share code, notes, and snippets.

@yalab
Last active April 29, 2016 07:28
Show Gist options
  • Save yalab/8690e834cc5fbc791e123fd0c85a8cf3 to your computer and use it in GitHub Desktop.
Save yalab/8690e834cc5fbc791e123fd0c85a8cf3 to your computer and use it in GitHub Desktop.
require 'net/imap'
imap = Net::IMAP.new('imap.gmail.com', 993, true)
imap.login(ENV["GMAIL_USER"], ENV["GMAIL_PASSWORD"])
imap.select("Inbox")
listprefix = "[Imap]/"
listname = "PROCESSED"
unless imap.list(listprefix, listname)
imap.create("#{listprefix}#{listname}")
end
ids = imap.search(["SINCE", "1-Apr-2000"])
while id = ids.pop
response = imap.copy(id, "#{listprefix}#{listname}")
unless response.data.code
ids.push(id)
next
end
imap.store(id, "+FLAGS", [:Deleted])
end
imap.expunge
@yalab
Copy link
Author

yalab commented Apr 29, 2016

上手くいっている response

#<struct Net::IMAP::TaggedResponse tag="RUBY0009", name="OK", data=#<struct Net::IMAP::ResponseText code=#<struct Net::IMAP::ResponseCode name="COPYUID", data="56 8 13">, text=" (Success)">, raw_data="RUBY0009 OK [COPYUID 56 8 13] (Success)\r\n">

うまくいっていない response

#<struct Net::IMAP::TaggedResponse tag="RUBY0011", name="OK", data=#<struct Net::IMAP::ResponseText code=nil, text="Success">, raw_data="RUBY0011 OK Success\r\n">

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment