Пример #1
0
def DrawExceptionLabels(dc, x, rect, accountname, status = None, message = None, isHeader = False, exceptionListWidth = None):

    height = rect.height
    width = rect.width
    paddingx = 5
    alignment = wx.ALIGN_CENTER if isHeader else wx.ALIGN_LEFT

    statuswidth = 60
    sx = (exceptionListWidth if exceptionListWidth is not None else width)/20*9
    accountwidth = sx - paddingx - x
    mx = sx + statuswidth

    dc.SetPen(wx.Pen(wx.Color(200, 200, 200)))
    dc.DrawLine(sx, 0, sx, height)
    dc.DrawLine(mx, 0, mx, height)
    dc.DrawLine(0, height-1, width, height-1)

    dc.TextForeground = wx.BLACK #syscol(wx.SYS_COLOUR_HIGHLIGHTTEXT if self.IsSelected() else wx.SYS_COLOUR_WINDOWTEXT)

    labelheight = height - dc.Font.Descent/2

    accountrect = wx.Rect(x, 0, accountwidth, labelheight)
    dc.DrawTruncatedText(accountname, accountrect, alignment | wx.ALIGN_CENTER_VERTICAL)

    if status is not None and status != "None":
        x = sx + paddingx

        statusrect = wx.Rect(x, 0, statuswidth - 2*paddingx, labelheight)
        dc.DrawTruncatedText(status, statusrect, wx.ALIGN_CENTER | wx.ALIGN_CENTER_VERTICAL)

    if message is not None:
        x = mx + paddingx

        messagerect = wx.Rect(x, 0, width - x - paddingx, labelheight)
        dc.DrawTruncatedText(replace_newlines(message), messagerect, alignment | wx.ALIGN_CENTER_VERTICAL)
Пример #2
0
    def fromEmailMessage(cls, id, email, sendtime_if_error=None):
        'Creates an Email from a Python email.message.Message object.'
        encoding = email.get_content_charset()
        # parse name, address
        realname, email_address = parseaddr(email['From'])
        realname = unicode_hdr(realname, encoding)

        # parse date

        _email = email

        try:
            datetuple = parsedate(email['Date'])
            sendtime = datetime(*datetuple[:7])
        except Exception:
            traceback.print_exc()
            print >> sys.stderr, 'using %s for "sendtime" instead' % sendtime_if_error
            sendtime = sendtime_if_error

        try:
            attachments = find_attachments(email)
        except:
            attachments = {}
        part = find_part(email, ('text/plain', 'text/html'))

        if part is None:
            content = u''

        else:
            content = parse_content(part)

        content = replace_newlines(content)

        prev_length = pref('email.preview_length', 200)
        if len(content) > prev_length:
            content = content[:prev_length] + '...'
        else:
            content

        email = cls(id,
                    realname,
                    email_address,
                    sendtime,
                    email['Subject'],
                    content=content,
                    attachments=attachments)

        return email
Пример #3
0
    def fromEmailMessage(cls, id, email, sendtime_if_error=None):
        "Creates an Email from a Python email.message.Message object."
        encoding = email.get_content_charset()
        # parse name, address
        realname, email_address = parseaddr(email["From"])
        realname = unicode_hdr(realname, encoding)

        # parse date

        _email = email

        try:
            datetuple = parsedate(email["Date"])
            sendtime = datetime(*datetuple[:7])
        except Exception:
            traceback.print_exc()
            print >> sys.stderr, 'using %s for "sendtime" instead' % sendtime_if_error
            sendtime = sendtime_if_error

        try:
            attachments = find_attachments(email)
        except:
            attachments = {}
        part = find_part(email, ("text/plain", "text/html"))

        if part is None:
            content = u""

        else:
            content = parse_content(part)

        content = replace_newlines(content)

        prev_length = pref("email.preview_length", 200)
        if len(content) > prev_length:
            content = content[:prev_length] + "..."
        else:
            content

        email = cls(id, realname, email_address, sendtime, email["Subject"], content=content, attachments=attachments)

        return email