コード例 #1
0
ファイル: __init__.py プロジェクト: HieronymusCH/TaskCoach
def readMail(filename, readContent=True):
    subject = None
    content = ""
    encoding = None
    s = 0
    rx = re.compile("charset=([-0-9a-zA-Z]+)")

    for line in file(filename, "r"):
        if s == 0:
            if line.lower().startswith("subject:"):
                subject = line[8:].strip()
            if line.strip() == "":
                if not readContent:
                    break
                s = 1
            mt = rx.search(line)
            if mt:
                encoding = mt.group(1)
        elif s == 1:
            content += line

    if encoding is None:
        encoding = chardet.detect(content)["encoding"]
    if encoding is None:
        encoding = "utf-8"

    if subject is None:
        subject = _("Untitled e-mail")
    else:
        subject = subject.decode(encoding)

    content = content.decode(encoding)

    return subject, content
コード例 #2
0
ファイル: __init__.py プロジェクト: dfainstein/seng_taskcoach
def readMail(filename, readContent=True):
    # FIXME: Why not use the email package?
    subject = None
    content = ''
    encoding = None
    s = 0
    rx = re.compile('charset=([-0-9a-zA-Z]+)')

    for line in file(filename, 'r'):
        if s == 0:
            if line.lower().startswith('subject:'):
                subject = line[8:].strip() # FIXME: subject lines may be continued on the next line
            if line.strip() == '':
                if not readContent:
                    break
                s = 1
            mt = rx.search(line)
            if mt:
                encoding = mt.group(1)
        elif s == 1:
            content += line

    if encoding is None:
        # Don't try to guess every time. When there are many e-mails
        # with big attachments, it may take *very* long.

        try:
            encoding = wx.Locale_GetSystemEncodingName()
            if not encoding:
                # This happens on Mac OS...
                encoding = 'UTF-8'
            content.decode(encoding)
        except UnicodeError:
            encoding = chardet.detect(content)['encoding']

    if subject:
        try:
            decoded_subject = u''.join((part[0].decode(part[1]) if part[1] else part[0]) for part in email.header.decode_header(subject))
        except UnicodeDecodeError:
            decoded_subject = subject.decode(encoding)
        subject = decoded_subject
    else:
        subject = _('Untitled e-mail')
    
    content = content.decode(encoding)
    return subject, content
コード例 #3
0
def readMail(filename, readContent=True):
    subject = None
    content = ''
    encoding = None
    s = 0
    rx = re.compile('charset=([-0-9a-zA-Z]+)')

    for line in file(filename, 'r'):
        if s == 0:
            if line.lower().startswith('subject:'):
                subject = line[8:].strip()
            if line.strip() == '':
                if not readContent:
                    break
                s = 1
            mt = rx.search(line)
            if mt:
                encoding = mt.group(1)
        elif s == 1:
            content += line

    if encoding is None:
        # Don't try to guess every time. When there are many e-mails
        # with big attachments, it may take *very* long.

        try:
            encoding = wx.Locale_GetSystemEncodingName()
            if not encoding:
                # This happens on Mac OS...
                encoding = 'UTF-8'
            content.decode(encoding)
        except UnicodeError:
            encoding = chardet.detect(content)['encoding']

    subject = _('Untitled e-mail') if subject is None else subject.decode(
        encoding)
    content = content.decode(encoding)
    return subject, content
コード例 #4
0
def readMail(filename, readContent=True):
    subject = None
    content = ''
    encoding = None
    s = 0
    rx = re.compile('charset=([-0-9a-zA-Z]+)')

    for line in file(filename, 'r'):
        if s == 0:
            if line.lower().startswith('subject:'):
                subject = line[8:].strip()
            if line.strip() == '':
                if not readContent:
                    break
                s = 1
            mt = rx.search(line)
            if mt:
                encoding = mt.group(1)
        elif s == 1:
            content += line

    if encoding is None:
        # Don't try to guess every time. When there are many e-mails
        # with big attachments, it may take *very* long.

        try:
            encoding = wx.Locale_GetSystemEncodingName()
            if not encoding:
                # This happens on Mac OS...
                encoding = 'UTF-8'
            content.decode(encoding)
        except UnicodeError:
            encoding = chardet.detect(content)['encoding']

    subject = _('Untitled e-mail') if subject is None else subject.decode(encoding)
    content = content.decode(encoding)
    return subject, content
コード例 #5
0
    def __init__(self, filename, *args, **kwargs):
        super(CSVImportOptionsPage, self).__init__(*args, **kwargs)

        self.delimiter = wx.Choice(self, wx.ID_ANY)
        self.delimiter.Append(_('Comma'))
        self.delimiter.Append(_('Tab'))
        self.delimiter.Append(_('Space'))
        self.delimiter.Append(_('Colon'))
        self.delimiter.Append(_('Semicolon'))
        self.delimiter.SetSelection(0)

        self.quoteChar = wx.Choice(self, wx.ID_ANY)
        self.quoteChar.Append(_('Simple quote'))
        self.quoteChar.Append(_('Double quote'))
        self.quoteChar.SetSelection(1)

        self.quotePanel = wx.Panel(self, wx.ID_ANY)
        self.doubleQuote = wx.RadioButton(self.quotePanel, wx.ID_ANY, _('Double it'))
        self.doubleQuote.SetValue(True)
        self.escapeQuote = wx.RadioButton(self.quotePanel, wx.ID_ANY, _('Escape with'))
        self.escapeChar = wx.TextCtrl(self.quotePanel, wx.ID_ANY, '\\', size=(50, -1))
        self.escapeChar.Enable(False)
        self.escapeChar.SetMaxLength(1)

        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.Add(self.doubleQuote, 1, wx.ALL, 3)
        hsizer.Add(self.escapeQuote, 1, wx.ALL, 3)
        hsizer.Add(self.escapeChar, 1, wx.ALL, 3)
        self.quotePanel.SetSizer(hsizer)
        
        self.importSelectedRowsOnly = wx.CheckBox(self, wx.ID_ANY, _('Import only the selected rows'))
        self.importSelectedRowsOnly.SetValue(False)

        self.hasHeaders = wx.CheckBox(self, wx.ID_ANY, _('First line describes fields'))
        self.hasHeaders.SetValue(True)

        self.grid = gridlib.Grid(self)
        self.grid.SetRowLabelSize(0)
        self.grid.SetColLabelSize(0)
        self.grid.CreateGrid(0, 0)
        self.grid.EnableEditing(False)
        self.grid.SetSelectionMode(self.grid.wxGridSelectRows)

        vsizer = wx.BoxSizer(wx.VERTICAL)
        gridSizer = wx.FlexGridSizer(0, 2)

        gridSizer.Add(wx.StaticText(self, wx.ID_ANY, _('Delimiter')), 0, wx.ALIGN_CENTRE_VERTICAL|wx.ALL, 3)
        gridSizer.Add(self.delimiter, 0, wx.ALL, 3)

        gridSizer.Add(wx.StaticText(self, wx.ID_ANY, _('Quote character')), 0, wx.ALIGN_CENTRE_VERTICAL|wx.ALL, 3)
        gridSizer.Add(self.quoteChar, 0, wx.ALL, 3)

        gridSizer.Add(wx.StaticText(self, wx.ID_ANY, _('Escape quote')), 0, wx.ALIGN_CENTRE_VERTICAL|wx.ALL, 3)
        gridSizer.Add(self.quotePanel, 0, wx.ALL, 3)

        gridSizer.Add(self.importSelectedRowsOnly, 0, wx.ALL, 3)
        gridSizer.Add((0, 0))

        gridSizer.Add(self.hasHeaders, 0, wx.ALL, 3)
        gridSizer.Add((0, 0))

        gridSizer.AddGrowableCol(1)
        vsizer.Add(gridSizer, 0, wx.EXPAND|wx.ALL, 3)

        vsizer.Add(self.grid, 1, wx.EXPAND|wx.ALL, 3)

        self.SetSizer(vsizer)

        self.headers = None

        self.filename = filename
        self.encoding = chardet.detect(file(filename, 'rb').read())['encoding']
        self.OnOptionChanged(None)

        wx.EVT_CHOICE(self.delimiter, wx.ID_ANY, self.OnOptionChanged)
        wx.EVT_CHOICE(self.quoteChar, wx.ID_ANY, self.OnOptionChanged)
        wx.EVT_CHECKBOX(self.importSelectedRowsOnly, wx.ID_ANY, self.OnOptionChanged)
        wx.EVT_CHECKBOX(self.hasHeaders, wx.ID_ANY, self.OnOptionChanged)
        wx.EVT_RADIOBUTTON(self.doubleQuote, wx.ID_ANY, self.OnOptionChanged)
        wx.EVT_RADIOBUTTON(self.escapeQuote, wx.ID_ANY, self.OnOptionChanged)
        wx.EVT_TEXT(self.escapeChar, wx.ID_ANY, self.OnOptionChanged)
コード例 #6
0
    def __init__(self, filename, *args, **kwargs):
        super(CSVImportOptionsPage, self).__init__(*args, **kwargs)

        self.delimiter = wx.Choice(self, wx.ID_ANY)
        self.delimiter.Append(_('Comma'))
        self.delimiter.Append(_('Tab'))
        self.delimiter.Append(_('Space'))
        self.delimiter.Append(_('Colon'))
        self.delimiter.Append(_('Semicolon'))
        self.delimiter.Append(_('Pipe'))
        self.delimiter.SetSelection(0)

        self.date = wx.Choice(self)
        self.date.Append(_('DD/MM (day first)'))
        self.date.Append(_('MM/DD (month first)'))
        self.date.SetSelection(0)

        self.quoteChar = wx.Choice(self, wx.ID_ANY)
        self.quoteChar.Append(_('Simple quote'))
        self.quoteChar.Append(_('Double quote'))
        self.quoteChar.SetSelection(1)

        self.quotePanel = wx.Panel(self, wx.ID_ANY)
        self.doubleQuote = wx.RadioButton(self.quotePanel, wx.ID_ANY,
                                          _('Double it'))
        self.doubleQuote.SetValue(True)
        self.escapeQuote = wx.RadioButton(self.quotePanel, wx.ID_ANY,
                                          _('Escape with'))
        self.escapeChar = wx.TextCtrl(self.quotePanel,
                                      wx.ID_ANY,
                                      '\\',
                                      size=(50, -1))
        self.escapeChar.Enable(False)
        self.escapeChar.SetMaxLength(1)

        hsizer = wx.BoxSizer(wx.HORIZONTAL)
        hsizer.Add(self.doubleQuote, 1, wx.ALL, 3)
        hsizer.Add(self.escapeQuote, 1, wx.ALL, 3)
        hsizer.Add(self.escapeChar, 1, wx.ALL, 3)
        self.quotePanel.SetSizer(hsizer)

        self.importSelectedRowsOnly = wx.CheckBox(
            self, wx.ID_ANY, _('Import only the selected rows'))
        self.importSelectedRowsOnly.SetValue(False)

        self.hasHeaders = wx.CheckBox(self, wx.ID_ANY,
                                      _('First line describes fields'))
        self.hasHeaders.SetValue(True)

        self.grid = gridlib.Grid(self)
        self.grid.SetRowLabelSize(0)
        self.grid.SetColLabelSize(0)
        self.grid.CreateGrid(0, 0)
        self.grid.EnableEditing(False)
        self.grid.SetSelectionMode(self.grid.wxGridSelectRows)

        vsizer = wx.BoxSizer(wx.VERTICAL)
        gridSizer = wx.FlexGridSizer(0, 2)

        gridSizer.Add(wx.StaticText(self, wx.ID_ANY, _('Delimiter')), 0,
                      wx.ALIGN_CENTRE_VERTICAL | wx.ALL, 3)
        gridSizer.Add(self.delimiter, 0, wx.ALL, 3)

        gridSizer.Add(wx.StaticText(self, wx.ID_ANY, _('Date format')), 0,
                      wx.ALIGN_CENTER_VERTICAL | wx.ALL, 3)
        gridSizer.Add(self.date, 0, wx.ALL, 3)

        gridSizer.Add(wx.StaticText(self, wx.ID_ANY, _('Quote character')), 0,
                      wx.ALIGN_CENTRE_VERTICAL | wx.ALL, 3)
        gridSizer.Add(self.quoteChar, 0, wx.ALL, 3)

        gridSizer.Add(wx.StaticText(self, wx.ID_ANY, _('Escape quote')), 0,
                      wx.ALIGN_CENTRE_VERTICAL | wx.ALL, 3)
        gridSizer.Add(self.quotePanel, 0, wx.ALL, 3)

        gridSizer.Add(self.importSelectedRowsOnly, 0, wx.ALL, 3)
        gridSizer.Add((0, 0))

        gridSizer.Add(self.hasHeaders, 0, wx.ALL, 3)
        gridSizer.Add((0, 0))

        gridSizer.AddGrowableCol(1)
        vsizer.Add(gridSizer, 0, wx.EXPAND | wx.ALL, 3)

        vsizer.Add(self.grid, 1, wx.EXPAND | wx.ALL, 3)

        self.SetSizer(vsizer)

        self.headers = None

        self.filename = filename
        self.encoding = chardet.detect(file(filename, 'rb').read())['encoding']
        self.OnOptionChanged(None)

        wx.EVT_CHOICE(self.delimiter, wx.ID_ANY, self.OnOptionChanged)
        wx.EVT_CHOICE(self.quoteChar, wx.ID_ANY, self.OnOptionChanged)
        wx.EVT_CHECKBOX(self.importSelectedRowsOnly, wx.ID_ANY,
                        self.OnOptionChanged)
        wx.EVT_CHECKBOX(self.hasHeaders, wx.ID_ANY, self.OnOptionChanged)
        wx.EVT_RADIOBUTTON(self.doubleQuote, wx.ID_ANY, self.OnOptionChanged)
        wx.EVT_RADIOBUTTON(self.escapeQuote, wx.ID_ANY, self.OnOptionChanged)
        wx.EVT_TEXT(self.escapeChar, wx.ID_ANY, self.OnOptionChanged)