Created
April 23, 2009 10:37
-
-
Save mayuki/100447 to your computer and use it in GitHub Desktop.
Outlook IRC Access (with TwitterIrcGateway)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Outlook IRC Access (with TwitterIrcGateway) | |
# -*- coding: utf-8 -*- | |
import clr | |
import re | |
import Misuzilla.Applications.TwitterIrcGateway | |
import Misuzilla.Applications.TwitterIrcGateway.AddIns.Console | |
from System import * | |
from System.Collections.Generic import * | |
from System.Diagnostics import Trace | |
from System.Runtime.InteropServices import Marshal | |
from Misuzilla.Applications.TwitterIrcGateway.AddIns.Console import Context | |
from Misuzilla.Applications.TwitterIrcGateway.AddIns.DLRIntegration import DLRContext | |
from Misuzilla.Net.Irc import * | |
class OutlookConsole(object): | |
def __init__(self, channel_name, session, server): | |
self.channel_name = channel_name | |
self.session = session | |
self.server = server | |
def getApplication(self): | |
return self.app | |
def setup(self): | |
Trace.WriteLine("OutlookConsole: Setup") | |
# Outlook | |
t = Type.GetTypeFromProgID("Outlook.Application") | |
self.app = Activator.CreateInstance(t) | |
self.app.NewMailEx += self.onNewMailEx | |
self.app.Reminder += self.onReminder | |
# Unload | |
self.session.AddInManager.GetAddIn(Misuzilla.Applications.TwitterIrcGateway.AddIns.DLRIntegration.DLRIntegrationAddIn).BeforeUnload += self.onBeforeUnload | |
# Console | |
self.console = Misuzilla.Applications.TwitterIrcGateway.AddIns.Console.Console() | |
self.console.Attach(self.channel_name, self.server, self.session, DLRContext[OutlookContext].GetProxyType("Outlook", OutlookContext)) | |
Trace.WriteLine("OutlookConsole: Setup done") | |
def cleanup(self): | |
Trace.WriteLine("OutlookConsole: Cleanup") | |
# Console | |
self.console.Detach() | |
# Outlook | |
self.app.NewMailEx -= self.onNewMailEx | |
self.app.Reminder -= self.onReminder | |
Marshal.ReleaseComObject(self.app) | |
self.app = None | |
Trace.WriteLine("OutlookConsole: Cleanup done") | |
def send_notice(self, sender, message): | |
for line in message.split("\n"): | |
notice_msg = NoticeMessage(self.channel_name, line) | |
notice_msg.SenderNick = sender | |
self.session.Send(notice_msg) | |
#region Events | |
def onBeforeUnload(self, sender, args): | |
self.cleanup() | |
def onNewMailEx(self, entryIDCollection): | |
for entryID in entryIDCollection.split(','): | |
mail = self.app.Session.GetItemFromID(entryID) | |
self.send_notice("Inbox", ("%s | %s" % (mail.SentOnBehalfOfName, mail.Subject))) | |
def onReminder(self, item): | |
self.send_notice("Reminder", ("%s [%s] | %s~%s" % (item.Subject, item.Location, item.Start, item.End))) | |
#endregion | |
class OutlookContext(Context): | |
def Initialize(self): | |
self.console_container = outlook_console | |
self.app = self.console_container.getApplication() | |
pass | |
outlook_console = OutlookConsole("#Outlook", Session, Server) | |
outlook_console.setup() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment