Sha256: f1840ed3a08c340172669f366ae1914bc950c6228a87491e108d1d249bce870e

Contents?: true

Size: 1.82 KB

Versions: 87

Compression:

Stored size: 1.82 KB

Contents

# $Id: imap.rb,v 1.1 2006/10/05 01:36:52 koheik Exp $

require "net/imap"
$:.unshift(File.dirname(__FILE__) + '/../lib')
require "net/ntlm"

Net::IMAP::debug = true

$host = "localhost"
$port = 143
$ssl = false
$user = nil
$passwd = nil

module Net
  class IMAP
    class NtlmAuthenticator
      def process(data)
        case @state
        when 1
          @state = 2
          t1 = Net::NTLM::Message::Type1.new()
          return t1.serialize
        when 2
          @state = 3
          t2 = Net::NTLM::Message.parse(data)
          t3 = t2.response({:user => @user, :password => @password}, {:ntlmv2 => (@ntlm_type == "ntlmv2")})
          return t3.serialize
        end
      end

      private

      def initialize(user, password, ntlm_type = "ntlmv2")
        @user = user
        @password = password
        @ntlm_type = @ntlm_type
        @state = 1
      end
    end
    add_authenticator "NTLM", NtlmAuthenticator

    class ResponseParser
      def continue_req
        match(T_PLUS)
        if lookahead.symbol == T_CRLF # means empty message
          return ContinuationRequest.new(ResponseText.new(nil, ""), @str)
        end
        match(T_SPACE)
        return ContinuationRequest.new(resp_text, @str)
      end
    end
  end
end

unless $user and $passwd
  print "User name: "
  ($user = $stdin.readline).chomp!
  print "Password: "
  ($passwd = $stdin.readline).chomp!
end

imap = Net::IMAP.new($host, $port, $ssl)
imap.authenticate("NTLM", $user, $passwd)
imap.examine("Inbox")
# imap.search(["RECENT"]).each do |message_id|
# envelope = imap.fetch(message_id, "ENVELOPE")[0].attr["ENVELOPE"]
# from = envelope.from.nil? ? "" : envelope.from[0].name
# subject = envelope.subject
# puts "#{message_id} #{from}: \t#{subject}"
# end
imap.logout
# imap.disconnect

Version data entries

87 entries across 79 versions & 14 rubygems

Version Path
rubyntlm-0.6.5 examples/imap.rb
rubyntlm-0.6.4 examples/imap.rb
vagrant-unbundled-2.2.19.0 vendor/bundle/ruby/3.0.0/gems/rubyntlm-0.6.3/examples/imap.rb
vagrant-unbundled-2.2.18.0 vendor/bundle/ruby/3.0.0/gems/rubyntlm-0.6.3/examples/imap.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/3.0.0/gems/rubyntlm-0.6.3/examples/imap.rb
vagrant-unbundled-2.2.16.0 vendor/bundle/ruby/2.7.0/gems/rubyntlm-0.6.2/examples/imap.rb
rubyntlm-0.6.3 examples/imap.rb
vagrant-unbundled-2.2.14.0 vendor/bundle/ruby/2.7.0/gems/rubyntlm-0.6.2/examples/imap.rb
vagrant-unbundled-2.2.10.0 vendor/bundle/ruby/2.7.0/gems/rubyntlm-0.6.2/examples/imap.rb
vagrant-unbundled-2.2.9.0 vendor/bundle/ruby/2.7.0/gems/rubyntlm-0.6.2/examples/imap.rb
vagrant-unbundled-2.2.8.0 vendor/bundle/ruby/2.7.0/gems/rubyntlm-0.6.2/examples/imap.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.6.0/gems/rubyntlm-0.6.2/examples/imap.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.4.0/gems/rubyntlm-0.6.2/examples/imap.rb
vagrant-unbundled-2.2.7.0 vendor/bundle/ruby/2.7.0/gems/rubyntlm-0.6.2/examples/imap.rb
husc-0.2.1 vendor/bundle/gems/ntlm-http-0.1.1/examples/imap.rb
husc-0.2.0 vendor/bundle/gems/ntlm-http-0.1.1/examples/imap.rb
husc-0.1.1 vendor/bundle/gems/ntlm-http-0.1.1/examples/imap.rb
husc-0.1.0 vendor/bundle/gems/ntlm-http-0.1.1/examples/imap.rb
vagrant-unbundled-2.2.6.2 vendor/bundle/ruby/2.6.0/gems/rubyntlm-0.6.2/examples/imap.rb
vagrant-unbundled-2.2.6.1 vendor/bundle/ruby/2.6.0/gems/rubyntlm-0.6.2/examples/imap.rb