def test_zcp_13036_69(session, store, message): rfc = open(MAILS_PATH.format('zcp-13036-6906a338.eml'), 'rb').read() dopt = inetmapi.delivery_options() inetmapi.IMToMAPI(session, store, None, message, rfc, dopt) props = message.GetProps([PR_INTERNET_CPID, PR_BODY_W], 0) assert GetCharsetByCP(props[0].Value) == "iso-8859-1" assert "Jänner" in props[1].Value
def test_zcp_13036_0d(session, store, message): rfc = open(MAILS_PATH.format('zcp-13036-0db504a2.eml'), 'rb').read() dopt = inetmapi.delivery_options() inetmapi.IMToMAPI(session, store, None, message, rfc, dopt) props = message.GetProps([PR_INTERNET_CPID, PR_BODY_W], 0) assert GetCharsetByCP(props[0].Value) == "utf-8" assert "zgłoszeń" in props[1].Value
class ZStore: def __init__(self, username): try: self.session = OpenECSession( username, '', os.getenv('ZARAFA_SOCKET', 'file:///var/run/zarafa')) except MAPIError, e: print "[MAIL-IMPORT] Unable to login using %s" % username raise e self.abook = self.session.OpenAddressBook(0, None, MAPI_UNICODE) self.store = GetDefaultStore(self.session) eid = self.store.GetReceiveFolder('IPM', 0)[0] self.dest = self.inbox = self.store.OpenEntry(eid, None, MAPI_MODIFY) self.dopt = inetmapi.delivery_options() self.errors = 0
def __init__(self, folder=None, eml=None, ics=None, vcf=None, load=None, loads=None, attachments=True, create=False, mapiobj=None, entryid=None, content_flag=None, cache={}, save=True): self._eml = None self._architem = None self._folder = None self.mapiobj = mapiobj self._entryid = entryid self._content_flag = content_flag or 0 self._cache = cache if folder: self._folder = folder self.store = folder.store self.server = folder.server if create: self.mapiobj = self.folder.mapiobj.CreateMessage(None, MAPI_ASSOCIATED if self.folder.content_flag & MAPI_ASSOCIATED else 0) self.store = self.folder.store self.server = server = self.store.server # XXX if _is_file(eml): eml = eml.read() if _is_file(ics): ics = ics.read() if _is_file(vcf): vcf = vcf.read() self._eml = eml if eml is not None: # options for CreateMessage: 0 / MAPI_ASSOCIATED dopt = inetmapi.delivery_options() inetmapi.IMToMAPI(server.mapisession, self.folder.store.mapiobj, None, self.mapiobj, self._eml, dopt) pass elif ics is not None: icm = icalmapi.CreateICalToMapi(self.mapiobj, server.ab, False) icm.ParseICal(ics, 'utf-8', 'UTC', self.user.mapiobj, 0) icm.GetItem(0, 0, self.mapiobj) elif vcf is not None: vcm = icalmapi.create_vcftomapi(self.mapiobj) vcm.parse_vcf(vcf) vcm.get_item(self.mapiobj) elif load is not None: self.load(load, attachments=attachments) elif loads is not None: self.loads(loads, attachments=attachments) else: try: container_class = HrGetOneProp(self.folder.mapiobj, PR_CONTAINER_CLASS_W).Value except MAPIErrorNotFound: self.mapiobj.SetProps([SPropValue(PR_MESSAGE_CLASS_W, u'IPM.Note')]) else: if container_class == 'IPF.Contact': # TODO just skip first 4 chars? self.mapiobj.SetProps([SPropValue(PR_MESSAGE_CLASS_W, u'IPM.Contact')]) # TODO set all default props elif container_class == 'IPF.Appointment': self.mapiobj.SetProps([SPropValue(PR_MESSAGE_CLASS_W, u'IPM.Appointment')]) # TODO set all default props!! self.from_ = self.store.user self[PidLidAppointmentStateFlags] = 1 self[PidLidResponseStatus] = 1 # TODO move appt creation to appointment.py self[PidLidFInvited] = False if save: _utils._save(self.mapiobj)
import os import sys import locale import getopt import MAPI from MAPI.Util import * from MAPI.Time import * from MAPI.Struct import * import inetmapi # @todo add ignore empty recipients sopt = inetmapi.sending_options() sopt.no_recipients_workaround = True sopt.add_received_date = True dopt = inetmapi.delivery_options() verbose = False class emptyCompany: pass class emptyUser: pass def CheckUser(store, abook): abeid = store.GetProps([PR_MAILBOX_OWNER_ENTRYID], 0) user = abook.OpenEntry(abeid[0].Value, None, 0) enabled = user.GetProps([PR_EC_ENABLED_FEATURES], 0)
def dopt(): dopt = inetmapi.delivery_options() dopt.ascii_upgrade = "utf-8" return dopt
def __init__(self, parent=None, eml=None, ics=None, vcf=None, load=None, loads=None, attachments=True, create=False, mapiobj=None, entryid=None, content_flag=None, save=True): self.emlfile = None self._architem = None self._folder = None self.mapiobj = mapiobj self._entryid = entryid self._content_flag = content_flag or 0 if isinstance(parent, _folder.Folder): self._folder = parent self.store = parent.store self.server = parent.server elif isinstance(parent, _store.Store): self.store = store self.server = store.server if create: self.mapiobj = self.folder.mapiobj.CreateMessage( None, MAPI_ASSOCIATED if self.folder.content_flag & MAPI_ASSOCIATED else 0) self.store = self.folder.store self.server = server = self.store.server # XXX if _is_file(eml): eml = eml.read() if _is_file(ics): ics = ics.read() if _is_file(vcf): vcf = vcf.read() self.emlfile = eml if eml is not None: # options for CreateMessage: 0 / MAPI_ASSOCIATED dopt = inetmapi.delivery_options() inetmapi.IMToMAPI(server.mapisession, self.folder.store.mapiobj, None, self.mapiobj, self.emlfile, dopt) pass elif ics is not None: icm = icalmapi.CreateICalToMapi(self.mapiobj, server.ab, False) icm.ParseICal(ics, 'utf-8', '', None, 0) icm.GetItem(0, 0, self.mapiobj) elif vcf is not None: vcm = icalmapi.create_vcftomapi(self.mapiobj) vcm.parse_vcf(vcf) vcm.get_item(self.mapiobj) elif load is not None: self.load(load, attachments=attachments) elif loads is not None: self.loads(loads, attachments=attachments) else: try: container_class = HrGetOneProp(self.folder.mapiobj, PR_CONTAINER_CLASS).Value except MAPIErrorNotFound: self.mapiobj.SetProps( [SPropValue(PR_MESSAGE_CLASS_W, u'IPM.Note')]) else: if container_class == 'IPF.Contact': # XXX just skip first 4 chars? self.mapiobj.SetProps([ SPropValue(PR_MESSAGE_CLASS_W, u'IPM.Contact') ]) # XXX set default props elif container_class == 'IPF.Appointment': self.mapiobj.SetProps([ SPropValue(PR_MESSAGE_CLASS_W, u'IPM.Appointment') ]) # XXX set default props if save: self.mapiobj.SaveChanges(KEEP_OPEN_READWRITE)