コード例 #1
0
ファイル: zimbra.py プロジェクト: giacomos/vnccollab.theme
    def get_email(self, eid):
        """Returns conversation emails by given id.

        It also marks conversation as read.
        """
        if not eid:
            return {'error': _(u"Conversation id is not valid.")}

        result = self.client.get_email(eid)
        thread = []
        for item in result:
            from_ = [su(e._getAttr('p')) for e in item.e
                        if e._getAttr('t') == 'f']
            from_ = from_[0] if len(from_) else ''
            to = u', '.join([su(e._getAttr('d')) for e in item.e
                        if e._getAttr('t') == 't'])

            thread.append({
                'from': from_,
                'to': to,
                'body': findMsgBody(item),
                'id': item._getAttr('_orig_id'),
                'date': item._getAttr('d'),
            })

        return {'conversation': '<br />'.join([t['from'] + ': ' + t['body']
            for t in thread])}
コード例 #2
0
ファイル: zimbrautil.py プロジェクト: vnc-biz/vnccollab.theme
    def _dict_from_mail(self, mail):
        """Converts a zimbra mail into a dictionary"""
        people = getattr(mail, 'e', [])
        if not people:
            people = []
        elif not isinstance(people, list):
            people = [people]

        # prepare subject
        subject = getattr(mail, 'su', '') or 'No Subject'

        dct = {
            'subject': su(subject),
            'body': u'%s (%s) - %s - %s' % (u', '.join([p._getAttr('d')
                    for p in people]), mail._getAttr('n'), su(mail.su),
                    su(getattr(mail, 'fr', ''))),
            'unread': u'u' in (mail._getAttr('f') or ''),
            'id': mail._getAttr('_orig_id'),
            'date': mail._getAttr('d'),
            'cid': mail._getAttr('cid'),
        }
        return dct
コード例 #3
0
ファイル: zimbrautil.py プロジェクト: vnc-biz/vnccollab.theme
    def get_email_thread(self, eid):
        """Returns conversation emails by given id.

        It also marks conversation as read.
        """
        result = self.get_email(eid)

        thread = []
        for item in result:
            from_ = [su(e._getAttr('p')) for e in item.e
                        if e._getAttr('t') == 'f']
            from_ = from_[0] if len(from_) else ''
            to = u', '.join([su(e._getAttr('d')) for e in item.e
                        if e._getAttr('t') == 't'])

            thread.append({
                'from': from_,
                'to': to,
                'body': item,
                'id': item._getAttr('_orig_id'),
                'date': item._getAttr('d'),
            })

            return thread
コード例 #4
0
ファイル: zimbra.py プロジェクト: giacomos/vnccollab.theme
def findMsgBody(node, format='text/html'):
    """Recursively goes over attachments and finds body"""
    if hasattr(node, '_name') and node._name == 'mp' and \
       hasattr(node, '_getAttr') and node._getAttr('body') == '1' and \
       node._getAttr('ct') == format and hasattr(node, 'content'):
        return su(node.content)

    if hasattr(node, 'mp'):
        mp = node.mp
        if not isinstance(mp, (types.ListType, types.TupleType)):
            mp = [mp]
        for sub_node in mp:
            body = findMsgBody(sub_node, format)
            if body:
                return body

    return u''
コード例 #5
0
ファイル: util.py プロジェクト: vnc-biz/vnccollab.zimbra
 def _get_credentials(self):
     member = api.user.get_current()
     username = member.getProperty('zimbra_username', '')
     password = member.getProperty('zimbra_password', '')
     # password could contain non-ascii chars, ensure it's properly encoded
     return username, su(password).encode('utf-8')
コード例 #6
0
 def anglicize(value):
   return su(value).replace(u'Ä',u'A')
コード例 #7
0
ファイル: util.py プロジェクト: clamor/vnccollab.redmine
 def _get_credentials(self):
     member = api.user.get_current()
     username = member.getProperty('redmine_username', '')
     password = member.getProperty('redmine_password', '')
     # password could contain non-ascii chars, ensure it's properly encoded
     return username, su(password).encode('utf-8')