Skip to content

Instantly share code, notes, and snippets.

@jelly
Created December 5, 2014 13:38
Show Gist options
  • Save jelly/5664f87caf17d79f75ee to your computer and use it in GitHub Desktop.
Save jelly/5664f87caf17d79f75ee to your computer and use it in GitHub Desktop.
AddKeyword
import MAPI
from MAPI.Util import *
from MAPI.Time import *
from MAPI.Tags import *
from MAPI.Struct import *
from plugintemplates import *
class addKeyword(IMapiDAgentPlugin):
def PostDelivery(self, session, addrbook, store, folder, message):
PS_INTERNET_HEADERS = DEFINE_OLEGUID(0x00020386, 0, 0)
NAMED_PROPS_INTERNET_HEADERS = [MAPINAMEID(PS_INTERNET_HEADERS, MNID_STRING, u'x-original-to'),]
namedprop_ids = message.GetIDsFromNames(NAMED_PROPS_INTERNET_HEADERS, 0)
namedprop_id = CHANGE_PROP_TYPE(namedprop_ids[0], PT_UNICODE)
prop = HrGetOneProp(message, namedprop_id).Value
elements = prop.split('-', 2)
if(len(elements) == 2):
try:
subelem = elements[1].decode('utf-8').split('@');
message.SetProps([SPropValue(namedprop_id, [subelem[0]])])
message.SaveChanges(0)
except:
self.logger.logFatal(sys.exc_info()[0])
return MP_CONTINUE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment