{"id":1102,"date":"2009-10-27T11:08:15","date_gmt":"2009-10-27T10:08:15","guid":{"rendered":"http:\/\/www.devco.net\/?p=1102"},"modified":"2009-11-03T00:25:05","modified_gmt":"2009-11-02T23:25:05","slug":"using_ruby_netimap_with_plain_auth","status":"publish","type":"post","link":"https:\/\/www.devco.net\/archives\/2009\/10\/27\/using_ruby_netimap_with_plain_auth.php","title":{"rendered":"Using Ruby Net::IMAP with plain auth"},"content":{"rendered":"

I’ve had to help a client pull out sender addresses from a folder on a Zimbra server, Ruby supports IMAP but only with LOGIN and CRAM-MD5 methods while Zimbra wants PLAIN. Net::IMAP supports adding a new authenticator so it was pretty simple in the end:<\/p>\n

\n
\r\nclass ImapPlainAuthenticator\r\n  def process(data)\r\n    return \"#{@user}\\0#{@user}\\0#{@password}\"\r\n  end\r\n  \r\n  def initialize(user, password)\r\n    @user = user\r\n    @password = password\r\n  end\r\nend\r\n\r\nNet::IMAP::add_authenticator('PLAIN', ImapPlainAuthenticator)\r\n<\/pre>\n<\/blockquote>\n

And using it to retrieve the list of senders:<\/p>\n

\n
\r\nimap = Net::IMAP.new('imap.your.com')\r\n\r\nimap.authenticate('PLAIN', 'username', 'pass')\r\nimap.examine('INBOX\/subfolder')\r\nimap.search([\"ALL\"]).each do |message_id|\r\n    envelope = imap.fetch(message_id, \"ENVELOPE\")[0].attr[\"ENVELOPE\"]\r\n    puts \"#{envelope.from[0].mailbox}\"\r\nend\r\n<\/pre>\n<\/blockquote>\n

Very simple, took about 5 minutes and saved days of manual pain and suffering, result!<\/p>\n","protected":false},"excerpt":{"rendered":"

I’ve had to help a client pull out sender addresses from a folder on a Zimbra server, Ruby supports IMAP but only with LOGIN and CRAM-MD5 methods while Zimbra wants PLAIN. Net::IMAP supports adding a new authenticator so it was pretty simple in the end: class ImapPlainAuthenticator def process(data) return “#{@user}\\0#{@user}\\0#{@password}” end def initialize(user, password) […]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","footnotes":""},"categories":[1],"tags":[121,13],"_links":{"self":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1102"}],"collection":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/comments?post=1102"}],"version-history":[{"count":4,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1102\/revisions"}],"predecessor-version":[{"id":1106,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/posts\/1102\/revisions\/1106"}],"wp:attachment":[{"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/media?parent=1102"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/categories?post=1102"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devco.net\/wp-json\/wp\/v2\/tags?post=1102"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}