1#!/usr/bin/python 2 3import sys 4 5from AppKit import * 6from Foundation import * 7import objc 8 9MessageRuleClass = objc.runtime.MessageRule 10oldPerformActionsOnMessages_destinationStores_rejectedMessages_messagesToBeDeleted_ = MessageRuleClass.instanceMethodForSelector_("performActionsOnMessages:destinationStores:rejectedMessages:messagesToBeDeleted:") 11 12def performActionsOnMessages_destinationStores_rejectedMessages_messagesToBeDeleted_(self, messages, stores, rejectedMessages, messagesToBeDeleted): 13 NSLog('yes') 14 oldPerformActionsOnMessages_destinationStores_rejectedMessages_messagesToBeDeleted_(self, messages, stores, rejectedMessages, messagesToBeDeleted) 15 NSLog('done') 16 17objc.classAddMethods(MessageRuleClass, 18[performActionsOnMessages_destinationStores_rejectedMessages_messagesToBeDeleted_]) 19 20 21class ToyMailBundle2 (objc.runtime.MVMailBundle): 22 def applicationWillTerminate_ (self, notification): 23 NSLog('ToyMailBundle2 is shutting down') 24 NSNotificationCenter.defaultCenter().removeObserver_name_object_(self, 25None, None) 26 27 def init (self): 28 self = super(ToyMailBundle2, self).init() 29 if self: 30 NSLog('ToyMailBundle2 -init called') 31 NSNotificationCenter.defaultCenter().addObserver_selector_name_object_(self, 32 33 'applicationWillTerminate:', 34 35 NSApplicationWillTerminateNotification, 36 37 None) 38 return self 39 40 def initialize (cls): 41 cls.registerBundle() 42 NSLog('ToyMailBundle2 registered with Mail') 43 44 initialize = classmethod(initialize) 45