# Path: Wammu/Utils.py
# def SearchNumber(lst, number):
#     for i in range(len(lst)):
#         for x in lst[i]['Entries']:
#             if GetItemType(x['Type']) == 'phone' and NormalizeNumber(number) == NormalizeNumber(x['Value']):
#                 return i
#     return -1
# 
# Path: Wammu/MessageDisplay.py
# def SmsTextFormat(cfg, txt, dohtml=True, doxml=False):
#     if txt is None:
#         return ''
#     if cfg.Read('/Message/Format') == 'yes':
#         parts = []
#         arr = txt.split(' ')
#         for a in arr:
#             if re.match('^([a-z]+[^ ]*)?[A-Z].*[a-z]{2,}[A-Z]{2,}.*$', a) is not None:
#                 prevtype = 'p'
#                 if UnicodeConv(string.lowercase).find(a[0]) != -1:
#                     curtype = 'l'
#                 elif UnicodeConv(string.uppercase).find(a[0]) != -1:
#                     curtype = 'u'
#                 elif UnicodeConv(string.digits).find(a[0]) != -1:
#                     curtype = 'd'
#                 else:
#                     curtype = 'p'
# 
#                 s = a[0]
# 
#                 for x in a[1:]:
#                     if UnicodeConv(string.lowercase).find(x) != -1:
#                         nexttype = 'l'
#                     elif UnicodeConv(string.uppercase).find(x) != -1:
#                         nexttype = 'u'
#                     elif UnicodeConv(string.digits).find(x) != -1:
#                         nexttype = 'd'
#                     else:
#                         nexttype = 'p'
# 
#                     if curtype == nexttype:
#                         s += x
#                     else:
#                         if curtype == 'u' and nexttype == 'l' and prevtype == 'p' and len(s) == 1:
#                             curtype = 'l'
#                             prevtype = 'u'
#                             s += x
#                             continue
#                         if curtype == 'p':
#                             parts[-1] += s
#                         elif curtype == 'u':
#                             parts.append(s.lower())
#                         else:
#                             parts.append(s)
#                         s = x
#                         prevtype = curtype
#                         curtype = nexttype
# 
#                 if curtype == 'p':
#                     parts[-1] += s
#                 elif curtype == 'u':
#                     parts.append(s.lower())
#                 else:
#                     parts.append(s)
#                 s = x
#             else:
#                 parts.append(a)
#         ret = ' '.join(parts)
#     else:
#         ret = txt
#     if dohtml or doxml:
#         xmlsafe = xml.sax.saxutils.escape(ret)
#         if doxml:
#             return xmlsafe.replace('\n', '<br />')
#         else:
#             return xmlsafe.replace('\n', '<br>')
#     else:
#         return ret.replace('\n', ' ')


from Wammu.Utils import SearchNumber
from Wammu.MessageDisplay import SmsTextFormat
from email.MIMEAudio import MIMEAudio
from email.MIMEImage import MIMEImage
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
from hashlib import md5
import email.Utils
import time
import tempfile
import os
import wx
import Wammu.Data
    import gammu
    prepend = ''
    name = ''
    if lookuplist is not None:
        i = SearchNumber(lookuplist, sms['Number'])
        if i != -1:
            msg.add_header(HEADER_FORMAT % 'ContactID', str(i))
            name = '%s ' % lookuplist[i]['Name']

    for header in PARTS_TO_HEADER:
        msg.add_header(HEADER_FORMAT % header, unicode(sms['SMS'][0][header]))
    msg.add_header(HEADER_FORMAT % 'SMSC', sms['SMS'][0]['SMSC']['Number'])
    if sms['SMS'][0]['SMSCDateTime'] is not None:
        msg.add_header(
            HEADER_FORMAT % 'SMSCDate', DateToString(sms['SMS'][0]['SMSCDateTime'])
        )

    remote = '%s<%s@wammu.sms>' % (name, sms['Number'].replace(' ', '_'))
    local = cfg.Read('/MessageExport/From')

    if sms['SMS'][0]['Type'] == 'Submit':
        msg['To'] = remote
        msg['From'] = local
    else:
        msg['To'] = local
        msg['From'] = remote
        prepend = (
            'Received: from %s via GSM\n' % unicode(sms['SMS'][0]['SMSC']['Number'])
        ) + prepend

    if len(sms['Name']) > 0:

# Path: Wammu/Utils.py
# def SearchNumber(lst, number):
#     for i in range(len(lst)):
#         for x in lst[i]['Entries']:
#             if GetItemType(x['Type']) == 'phone' and NormalizeNumber(number) == NormalizeNumber(x['Value']):
#                 return i
#     return -1
# 
# Path: Wammu/MessageDisplay.py
# def SmsTextFormat(cfg, txt, dohtml=True, doxml=False):
#     if txt is None:
#         return ''
#     if cfg.Read('/Message/Format') == 'yes':
#         parts = []
#         arr = txt.split(' ')
#         for a in arr:
#             if re.match('^([a-z]+[^ ]*)?[A-Z].*[a-z]{2,}[A-Z]{2,}.*$', a) is not None:
#                 prevtype = 'p'
#                 if UnicodeConv(string.lowercase).find(a[0]) != -1:
#                     curtype = 'l'
#                 elif UnicodeConv(string.uppercase).find(a[0]) != -1:
#                     curtype = 'u'
#                 elif UnicodeConv(string.digits).find(a[0]) != -1:
#                     curtype = 'd'
#                 else:
#                     curtype = 'p'
# 
#                 s = a[0]
# 
#                 for x in a[1:]:
#                     if UnicodeConv(string.lowercase).find(x) != -1:
#                         nexttype = 'l'
#                     elif UnicodeConv(string.uppercase).find(x) != -1:
#                         nexttype = 'u'
#                     elif UnicodeConv(string.digits).find(x) != -1:
#                         nexttype = 'd'
#                     else:
#                         nexttype = 'p'
# 
#                     if curtype == nexttype:
#                         s += x
#                     else:
#                         if curtype == 'u' and nexttype == 'l' and prevtype == 'p' and len(s) == 1:
#                             curtype = 'l'
#                             prevtype = 'u'
#                             s += x
#                             continue
#                         if curtype == 'p':
#                             parts[-1] += s
#                         elif curtype == 'u':
#                             parts.append(s.lower())
#                         else:
#                             parts.append(s)
#                         s = x
#                         prevtype = curtype
#                         curtype = nexttype
# 
#                 if curtype == 'p':
#                     parts[-1] += s
#                 elif curtype == 'u':
#                     parts.append(s.lower())
#                 else:
#                     parts.append(s)
#                 s = x
#             else:
#                 parts.append(a)
#         ret = ' '.join(parts)
#     else:
#         ret = txt
#     if dohtml or doxml:
#         xmlsafe = xml.sax.saxutils.escape(ret)
#         if doxml:
#             return xmlsafe.replace('\n', '<br />')
#         else:
#             return xmlsafe.replace('\n', '<br>')
#     else:
#         return ret.replace('\n', ' ')


# Path: Wammu/MailWriter.py
from Wammu.Utils import SearchNumber
from Wammu.MessageDisplay import SmsTextFormat
from email.MIMEAudio import MIMEAudio
from email.MIMEImage import MIMEImage
from email.MIMEText import MIMEText
from email.MIMEMultipart import MIMEMultipart
from hashlib import md5
import email.Utils
import time
import tempfile
import os
import wx
import Wammu.Data
    import gammu

    prepend = ''
    name = ''
    if lookuplist is not None:
        i = SearchNumber(lookuplist, sms['Number'])
        if i != -1:
            msg.add_header(HEADER_FORMAT % 'ContactID', str(i))
            name = '%s ' % lookuplist[i]['Name']

    for header in PARTS_TO_HEADER:
        msg.add_header(HEADER_FORMAT % header, unicode(sms['SMS'][0][header]))
    msg.add_header(HEADER_FORMAT % 'SMSC', sms['SMS'][0]['SMSC']['Number'])
    if sms['SMS'][0]['SMSCDateTime'] is not None:
        msg.add_header(
            HEADER_FORMAT % 'SMSCDate', DateToString(sms['SMS'][0]['SMSCDateTime'])
        )

    remote = '%s<%s@wammu.sms>' % (name, sms['Number'].replace(' ', '_'))
    local = cfg.Read('/MessageExport/From')

    if sms['SMS'][0]['Type'] == 'Submit':
        msg['To'] = remote
        msg['From'] = local
    else:
        msg['To'] = local
        msg['From'] = remote
        prepend = (
            'Received: from %s via GSM\n' % unicode(sms['SMS'][0]['SMSC']['Number'])
        ) + prepend

    if len(sms['Name']) > 0:

        msg['Subject'] = SmsTextFormat(cfg, sms['Name'], False)