/usr/lib/python2.7/dist-packages/kopano/attachment.py is in python-kopano 8.5.5-0ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | """
Part of the high-level python bindings for Kopano
Copyright 2005 - 2016 Zarafa and its licensors (see LICENSE file)
Copyright 2016 - Kopano and its licensors (see LICENSE file)
"""
import sys
from MAPI.Tags import (
PR_EC_HIERARCHYID, PR_ATTACH_NUM, PR_ATTACH_MIME_TAG_W,
PR_ATTACH_LONG_FILENAME_W, PR_ATTACH_SIZE, PR_ATTACH_DATA_BIN,
IID_IAttachment
)
from MAPI.Defs import HrGetOneProp
from MAPI.Struct import MAPIErrorNotFound
from .properties import Properties
if sys.hexversion >= 0x03000000:
try:
from . import utils as _utils
except ImportError:
_utils = sys.modules[__package__+'.utils']
else:
import utils as _utils
class Attachment(Properties):
"""Attachment class"""
def __init__(self, mapiitem=None, entryid=None, mapiobj=None):
self._mapiitem = mapiitem
self._entryid = entryid
self._mapiobj = mapiobj
self._data = None
@property
def mapiobj(self):
if self._mapiobj:
return self._mapiobj
self._mapiobj = self._mapiitem.OpenAttach(
self._entryid, IID_IAttachment, 0
)
return self._mapiobj
@mapiobj.setter
def mapiobj(self, mapiobj):
self._mapiobj = mapiobj
@property
def hierarchyid(self):
return self.prop(PR_EC_HIERARCHYID).value
@property
def number(self):
try:
return HrGetOneProp(self.mapiobj, PR_ATTACH_NUM).Value
except MAPIErrorNotFound:
return 0
@property
def mimetype(self):
"""Mime-type"""
try:
return HrGetOneProp(self.mapiobj, PR_ATTACH_MIME_TAG_W).Value
except MAPIErrorNotFound:
return u''
@property
def filename(self):
"""Filename"""
try:
return HrGetOneProp(self.mapiobj, PR_ATTACH_LONG_FILENAME_W).Value
except MAPIErrorNotFound:
return u''
@property
def size(self):
"""Size"""
# XXX size of the attachment object, so more than just the attachment
# data
# XXX (useful when calculating store size, for example.. sounds
# interesting to fix here)
try:
return int(HrGetOneProp(self.mapiobj, PR_ATTACH_SIZE).Value)
except MAPIErrorNotFound:
return 0 # XXX
def __len__(self):
return self.size
@property
def data(self):
"""Binary data"""
if self._data is None:
self._data = _utils.stream(self.mapiobj, PR_ATTACH_DATA_BIN)
return self._data
# file-like behaviour
def read(self):
return self.data
@property
def name(self):
return self.filename
def __unicode__(self):
return u'Attachment("%s")' % self.name
|