diff -ruN msnlib-3.1/doc/Changelog msnlib-3.2/doc/Changelog
--- msnlib-3.1/doc/Changelog	2003-09-28 10:01:51.000000000 -0300
+++ msnlib-3.2/doc/Changelog	2003-09-29 09:19:11.000000000 -0300
@@ -1,3 +1,15 @@
+29 Sep 03 09.17.33 - Alberto <albertogli@telpin.com.ar>
+ * tag: 3.2 tag
+
+28 Sep 03 11.39.59 - Alberto <albertogli@telpin.com.ar>
+ * msn: handle some Hotmail messages, now we display unread mail and new mail
+	notifications
+ * msnsetup: display profile name in the final message
+ * msn: implement multi-user chat logging, so now chats that involve multiple
+	users get logged properly to a different file
+ * msnlib: fix the login procedure to handle redirects properly, and clean up
+	and comment the code so we don't get lost in the parsing
+
 28 Sep 03 10.01.35 - Alberto <albertogli@telpin.com.ar>
  * tag: 3.1 tag
 
diff -ruN msnlib-3.1/doc/log_format msnlib-3.2/doc/log_format
--- msnlib-3.1/doc/log_format	2003-01-20 14:26:15.000000000 -0300
+++ msnlib-3.2/doc/log_format	2003-09-29 09:20:14.000000000 -0300
@@ -1,7 +1,14 @@
 
-This document describes the msn client log format
+This document describes the msn client log format.
 
-It's very simple:
+The files are named only with the email address of the sender/receiver; except
+for the multi-user chats (that is, a chat with more than you and somebody else
+involved) where the name is composed of 'M::' and then the list of
+participants (excluding yourself) sorted in alphabetical order, separated by
+commas (',').
+
+
+The format is very simple:
 
 Day/Month/Year HH:MM:SS email ID text
 
@@ -9,12 +16,20 @@
 	'>>>' if the text is an outgoing message
 	'<<<' if the text is an incoming message
 	'***' if the text refers to a new status
+	'+++' if the text refers to multi-user chats (joining and leaving)
+
+and email is the email of the user you send the message to/got a message from,
+except on the multi-user chat case, where for messages you sent your own
+email address is displayed.
+
 
 For example:
 Day/Month/Year HH:MM:SS email *** online
 Day/Month/Year HH:MM:SS email <<< incoming message
 Day/Month/Year HH:MM:SS email >>> outgoing message
 Day/Month/Year HH:MM:SS email *** offline
+Day/Month/Year HH:MM:SS email +++ join
+
 
 For multi-line messages, the message is indented with a tab, like:
 Day/Month/Year HH:MM:SS email <<<
diff -ruN msnlib-3.1/msn msnlib-3.2/msn
--- msnlib-3.1/msn	2003-09-28 10:01:00.000000000 -0300
+++ msnlib-3.2/msn	2003-09-29 09:18:17.000000000 -0300
@@ -391,7 +391,7 @@
 	"Null function, useful to void debug ones"
 	pass
 		
-def log_msg(email, type, msg, mtime = 0):
+def log_msg(email, type, msg, mtime = 0, users = []):
 	"""Logs the message or event of the 'type', related to 'email',
 	with the content 'msg', to a file in the specified directory.  See
 	documentation for more specific details, specially about
@@ -404,7 +404,18 @@
 		prepend = config['profile'] + '::'
 	else:
 		prepend = ''
-	file = config['history directory'] + '/' + prepend + email
+	if users:
+		# copy and sort the user list, so we log always to the same
+		# file regarding the order the users were joined
+		usorted = users[:]
+		usorted.sort()
+		file = config['history directory'] + '/' + prepend + 'M::'
+		for i in usorted:
+			file += i + ','
+		# strip the last ','
+		file = file[:-1]
+	else:
+		file = config['history directory'] + '/' + prepend + email
 	if not mtime:
 		mtime = time.time()
 	out = ''
@@ -424,6 +435,8 @@
 		out += '>>> ' + msg + '\n'
 	elif type == 'status':
 		out += '*** ' + msg + '\n'
+	elif type == 'multi':
+		out += '+++ ' + msg + '\n'
 	
 	fd = open(file, 'a')
 	fd.write(out)
@@ -1014,7 +1027,11 @@
 			return 'Message for %s queued for delivery' % nick
 		elif r == 2:
 			print_out_msg(nick, msg)
-			log_msg(email, 'out', msg)
+			if len(m.users[email].sbd.emails) > 1:
+				log_msg(m.email, 'out', msg, \
+					users = m.users[email].sbd.emails)
+			else:
+				log_msg(email, 'out', msg)
 		elif r == -2:
 			return 'Message too big'
 		else:
@@ -1097,6 +1114,7 @@
 		first_nick = email2nick(sbd.emails[0])
 		if not first_nick: first_nick = sbd.emails[0]
 		printl('\rUser %s left the chat with %s\n' % (nick, first_nick), c.green, 1)
+		log_msg(email, 'multi', 'left', users = sbd.emails)
 	msncb.cb_bye(md, type, tid, params, sbd)
 m.cb.bye = cb_bye
 
@@ -1107,14 +1125,6 @@
 	t = tid.split(' ')
 	email = t[0]
 	
-	# messages from hotmail are only when we connect, and send things
-	# regarding, aparently, hotmail issues. we ignore them (basically
-	# because i couldn't care less; however if somebody has intrest in
-	# these and provides some debug output i'll be happy to implement
-	# parsing).
-	if email == 'Hotmail':
-		return
-
 	# parse
 	lines = params.split('\n')
 	headers = {}
@@ -1123,14 +1133,47 @@
 		# end of headers
 		if i == '\r':
 			break
-		tv = i.split(':')
+		tv = i.split(':', 1)
 		type = tv[0]
-		value = string.join(tv[1:], ':')
-		value = string.strip(value)
+		value = tv[1].strip()
 		headers[type] = value
 		eoh += 1
-	
 	eoh +=1
+	
+	# handle special hotmail messages
+	if email == 'Hotmail':
+		if not headers.has_key('Content-Type'):
+			return
+		hotmail_info = {}
+		
+		# parse the body
+		for i in lines:
+			i = i.strip()
+			if not i:
+				continue
+			tv = i.split(':', 1)
+			type = tv[0]
+			value = tv[1].strip()
+			hotmail_info[type] = value
+					
+		msnlib.debug(params)
+		if headers['Content-Type'] == 'text/x-msmsgsinitialemailnotification; charset=UTF-8':
+			newmsgs = int(hotmail_info['Inbox-Unread'])
+			if not newmsgs:
+				return
+			printl('\rYou have %s unread email(s)' % str(newmsgs) \
+				+ ' in your Hotmail account\n', c.green, 1)
+		elif headers['Content-Type'] == 'text/x-msmsgsemailnotification; charset=UTF-8':
+			from_name = hotmail_info['From']
+			from_addr = hotmail_info['From-Addr']
+			subject = hotmail_info['Subject']
+			printl('\rYou have just received an email in your' + \
+				' Hotmail account:\n', c.green, 1)
+			printl('\r\tFrom: %s (%s)\n' % (from_name, from_addr),
+				c.green, 1)
+			printl('\r\tSubject: %s\n' % subject, c.green, 1)
+		return
+	
 	if headers.has_key('Content-Type') and headers['Content-Type'] == 'text/x-msmsgscontrol':
 		# the typing notices
 		nick = email2nick(email)
@@ -1152,7 +1195,11 @@
 		m.users[email].priv['typing'] = 0
 		printl('\r')
 		print_inc_msg(email, lines, eoh)
-		log_msg(email, 'in', string.join(lines[eoh:], '\n'))
+		if len(sbd.emails) > 1:
+			log_msg(email, 'in', string.join(lines[eoh:], '\n'), \
+				users = sbd.emails)
+		else:
+			log_msg(email, 'in', string.join(lines[eoh:], '\n'))
 
 		# append the message to the history, keeping it below the configured limit
 		if len(history_ring) > config['history size']: 
@@ -1174,6 +1221,8 @@
 		if not first_nick: first_nick = sbd.emails[0]
 		printl('\rUser %s has joined the chat with %s\n' % \
 			(nick, first_nick), c.green, 1)
+		log_msg(email, 'multi', 'join', \
+			users = sbd.emails + [email])
 	elif len(sbd.msgqueue) > 0:
 		printl('\rFlushing messages for %s:\n' % nick, c.green, 1)
 		for msg in sbd.msgqueue:
@@ -1202,6 +1251,8 @@
 		else:
 			printl('\rUser %s has joined the chat with %s\n' % \
 				(nick, first_nick), c.green, 1)
+			log_msg(email, 'multi', 'join', \
+				users = sbd.emails + [email])
 	msncb.cb_iro(md, type, tid, params, sbd)
 m.cb.iro = cb_iro
 
@@ -1294,7 +1345,7 @@
 #
 # now the real thing
 #
-printl('* MSN Client (3.1) *\n', c.yellow, 1)
+printl('* MSN Client (3.2) *\n', c.yellow, 1)
 
 # first, the configuration
 printl('Loading config... ', c.green, 1)
@@ -1471,7 +1522,6 @@
 	timeout = None		# must be None, not 0 because of select() semantics
 auto_away = 0
 
-
 # loop
 redraw_cli()
 while 1:
diff -ruN msnlib-3.1/msnlib.py msnlib-3.2/msnlib.py
--- msnlib-3.1/msnlib.py	2003-09-28 10:01:11.000000000 -0300
+++ msnlib-3.2/msnlib.py	2003-09-29 09:18:27.000000000 -0300
@@ -14,7 +14,7 @@
 """
 
 # constants
-VERSION = 0x0301
+VERSION = 0x0302
 LOGIN_HOST = 'messenger.hotmail.com'
 LOGIN_PORT = 1863
 
@@ -500,21 +500,23 @@
 		import urllib
 		import httplib
 		
+		# initial connection
+		debug('PASSPORT begin')
 		nexus = urllib.urlopen('https://nexus.passport.com/rdr/pprdr.asp')
 		h = nexus.headers
 		purl = h['PassportURLs']
-
+		
+		# parse the info
 		d = {}
 		for i in purl.split(','):
 		        key, val = i.split('=', 1)
 			d[key] = val
 		
+		# get the login server
 		login_server = 'https://' + d['DALogin']
 		login_host = d['DALogin'].split('/')[0]
-
-		ls = httplib.HTTPSConnection(login_host)
-
 		
+		# build the authentication headers
 		ahead =  'Passport1.4 OrgVerb=GET'
 		ahead += ',OrgURL=http%3A%2F%2Fmessenger%2Emsn%2Ecom'
 		ahead += ',sign-in=' + urllib.quote(self.email)
@@ -522,17 +524,38 @@
 		ahead += ',lc=1033,id=507,tw=40,fs=1,'
 		ahead += 'ru=http%3A%2F%2Fmessenger%2Emsn%2Ecom,ct=1062764229,'
 		ahead += 'kpp=1,kv=5,ver=2.1.0173.1,tpf=' + hash
-		
 		headers = { 'Authorization': ahead }
+		
+		# connect to the given server
+		debug('SSL Connect to %s' % login_server)
+		ls = httplib.HTTPSConnection(login_host)
+		
+		# make the request
+		debug('SSL GET')
 		ls.request('GET', login_server, '', headers)
 		resp = ls.getresponse()
 		
+		# loop if we get redirects until we get a definitive answer
+		debug('SSL Response %d' % resp.status)
+		while resp.status == 302:
+			login_server = resp.getheader('Location')
+			login_host = login_server.split('/')[2]
+			debug('SSL Redirect to %s' % login_server)
+			ls = httplib.HTTPSConnection(login_host)
+			headers = { 'Authorization': ahead }
+			ls.request('GET', login_server, '', headers)
+			resp = ls.getresponse()
+			debug('SSL Response %d' % resp.status)
+		
+		# now we have a definitive answer, if it's not 200 (success)
+		# just raise AuthError
 		if resp.status != 200:
 			# for now we raise 911, which means authentication
 			# failed; but maybe we can get more detailed
 			# information
-			raise 'AuthError', [911, 'SSL Authentication failed']
+			raise 'AuthError', [911, 'SSL Auth failed']
 
+		# and parse the headers to get the passport id
 		try:
 			ainfo = resp.getheader('Authentication-Info')
 		except:
diff -ruN msnlib-3.1/msnsetup msnlib-3.2/msnsetup
--- msnlib-3.1/msnsetup	2003-04-09 01:04:30.000000000 -0300
+++ msnlib-3.2/msnsetup	2003-09-28 15:31:27.000000000 -0300
@@ -77,7 +77,11 @@
 echo "Creating the configuration file ($RC)"
 create_rc "$RC"
 
-echo "Done! run 'msn' to start the client"
+RUN="msn"
+if [ "$1" ]; then
+	RUN="msn $1"
+fi
+echo "Done! run '$RUN' to start the client"
 
 
 
diff -ruN msnlib-3.1/setup.py msnlib-3.2/setup.py
--- msnlib-3.1/setup.py	2003-09-28 10:01:19.000000000 -0300
+++ msnlib-3.2/setup.py	2003-09-29 09:18:38.000000000 -0300
@@ -2,7 +2,7 @@
 from distutils.core import setup
 
 setup(name="msnlib",
-	version="3.1",
+	version="3.2",
 	description="MSN Messenger Library and Client",
 	author="Alberto Bertogli",
 	author_email="albertogli@telpin.com.ar",
diff -ruN msnlib-3.1/utils/msnlog.vim msnlib-3.2/utils/msnlog.vim
--- msnlib-3.1/utils/msnlog.vim	2003-01-20 14:26:15.000000000 -0300
+++ msnlib-3.2/utils/msnlog.vim	2003-09-28 12:39:50.000000000 -0300
@@ -1,6 +1,6 @@
 
 " Vim syntax file for msnlib logfiles
-" Alberto (albertogli@telpin.com.ar) 18/Sep/2002
+" Alberto (albertogli@telpin.com.ar) 28/Sep/2003
 
 " Use it to read your msnlib log files with color, makes it much easier.
 " Install it by copying to ~/.vim/syntax/msnlog.vim and then run (from vim)
@@ -15,6 +15,7 @@
 syntax match	mlogIMsg	"<<< .*$"
 syntax match	mlogOMsg	">>> .*$"
 syntax match	mlogStatus	".*\*\*\* .*$"
+syntax match	mlogMchat	"+++ .*$"
 syntax match	mlogDate	"^../.../.... ..:..:.."
 
 
@@ -22,6 +23,7 @@
 hi mlogIMsg		ctermfg=green
 hi mlogOMsg		ctermfg=cyan
 hi mlogStatus		ctermfg=yellow
+hi mlogMchat		ctermfg=yellow
 hi mlogMultiStr		ctermfg=magenta
 
 
