Esempio n. 1
0
    def get_named_attachment(self, itemid, name):
        """
        Return the attachment with name `name'
        """
        props = """
<t:FieldURI FieldURI="item:Attachments"/>
<t:FieldURI FieldURI="item:HasAttachments"/>"""

        item_id, item_chkey = itemid
        item = self.get_item((item_id, item_chkey), shape="IdOnly", extra_props=props)

        # Find all attachments
        et = ET.XML(item)
        attachments = elementsearch(et, t("ItemAttachment"), True)

        def name_filter(e):
            t_name = e.find(t("Name"))
            if t_name == None:
                return False
            return t_name.text == name

        attachments = filter(name_filter, attachments)

        # if len(attachments) > 1: oops?
        if len(attachments) == 0:
            return None

        # Just take the first for now
        attachment = attachments[0]
        attachment_id = attachment.find(t("AttachmentId")).attrib["Id"]

        return self.get_attachment(attachment_id)
Esempio n. 2
0
    def delete_named_attachment(self, itemid, name):
        attachment = self.get_named_attachment(itemid, name)
        at_elem = ET.XML(attachment)
        print attachment

        # TODO: feilsjekking
        a_id_elem = elementsearch(at_elem, t("AttachmentId"))
        a_id = a_id_elem.attrib["Id"]

        return self.delete_attachment(a_id)
Esempio n. 3
0
    def get_attached_note(self, itemid, name):
        """
        Get an attached note created by `createAttachedNote'
        """

        attachment = self.get_named_attachment(itemid, name)
        at_elem = ET.XML(attachment)  # feilsjekking

        body = elementsearch(at_elem, t("Body"))
        return body.text
Esempio n. 4
0
    def new(self, *args, **kws):
        xml = ET.XML(f(self, *args, **kws))
        body = elementsearch(xml, "{http://schemas.xmlsoap.org/soap/envelope}Body")

        if body == None:
            raise ValueError("Could not find <soap:Body/> element")

        soap_action = body.getchildren()[0].tag

        return self.soapconn.do_query("/ews/Exchange.asmx", f(*args, **kws), soap_action)
Esempio n. 5
0
    def get_all_calendar_items(self, extra_props=None):
        """
        Return all items with all needed properties
        """
        r = ET.XML(self.find_items("calendar", baseshape="IdOnly"))
        id_elems = elementsearch(r, t("ItemId"), all=True)
        item_ids = [(i.attrib["Id"], i.attrib["ChangeKey"]) for i in id_elems]
        if len(item_ids) == 0:
            return "<Items></Items>"

        if extra_props:
            return self.get_item(item_ids, shape="IdOnly", extra_props=extra_props)
        else:
            # By default, get items with body
            return self.get_item(item_ids, extra_props=["item:Body"])
Esempio n. 6
0
    def msquery(self, string, header=""):
        header += '<t:RequestServerVersion Version="Exchange2007_SP1"/>'
        query = """<?xml version="1.0" encoding="utf-8"?>
 <soap:Envelope
   xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns="%s" xmlns:t="%s">
   <soap:Header>%s</soap:Header>
     <soap:Body>
       %s
     </soap:Body>
   </soap:Envelope>""" % (
            messages,
            types,
            header,
            string,
        )

        # Handy for debugging last request
        f = open("/tmp/lastquery.xml", "a")
        f.write("\n\n\n" + query)
        f.close()

        try:
            xml = ET.XML(query)
        except ExpatError:
            e = sys.exc_value
            raise QueryError(str(e), query=query)

        body = elementsearch(xml, "{http://schemas.xmlsoap.org/soap/envelope/}Body")
        if body == None:
            raise QueryError("Could not find soap:Body element", query=query)

        soap_action = body.getchildren()[0].tag
        soap_action = re.sub("{", "", soap_action)
        soap_action = re.sub("}", "/", soap_action)

        return self.soapconn.do_query("/ews/Exchange.asmx", query, soap_action)