Skip to content

Instantly share code, notes, and snippets.

@sionide21
Created December 15, 2014 20:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sionide21/00e20740aa2619a1c603 to your computer and use it in GitHub Desktop.
Save sionide21/00e20740aa2619a1c603 to your computer and use it in GitHub Desktop.
A proxy to the office365 IMAP server to figure out what a client tis up to.
require 'openssl'
require 'socket'
Thread.abort_on_exception = true
server = TCPServer.new(1993)
n = 0
loop do
client = server.accept
n += 1
puts "[#{n}] New connection"
fork do
sock = TCPSocket.new('outlook.office365.com', 993)
ctx = OpenSSL::SSL::SSLContext.new
ctx.set_params(verify_mode: OpenSSL::SSL::VERIFY_NONE)
OpenSSL::SSL::SSLSocket.new(sock, ctx).tap do |server|
server.sync_close = true
server.connect
t = Thread.new do
while (line = server.gets)
puts "[#{n}]<- #{line.strip}"
client.write(line)
$stdout.flush
end
end
while (line = client.gets)
puts "[#{n}]-> #{line.strip}"
server.write(line)
$stdout.flush
end
t.join
end
client.close
puts "[#{n}] Connection closed"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment