# 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/Locales.py
# def ugettext(message):
#     if _TRANSLATION:
#         if six.PY2:
#             return _TRANSLATION.ugettext(message)
#         return _TRANSLATION.gettext(message)
#     return message


from Wammu.Utils import SearchNumber
from Wammu.MessageDisplay import SmsTextFormat
from Wammu.Locales import ugettext as _
from xml.sax.saxutils import escape
import Wammu.Data
import wx
import os
        smsxml += "        <dateenc>"
        smsxml += sms['DateTime'].strftime("%Y%m%d%H%M%S")
        smsxml += "</dateenc>\n"

    smsxml += "        <text>"
    smsxml += escape(text.encode('utf-8'))
    smsxml += "</text>\n"

    smsxml += "        <telephone>"
    smsxml += escape(sms['Number'].encode('utf-8'))
    smsxml += "</telephone>\n"

    smsxml += "        <contact>"
    smsxml += escape(contact.encode('utf-8'))
    smsxml += "</contact>\n"

    smsxml += "        <folder>"
    smsxml += str(sms['Folder'])
    smsxml += "</folder>\n"

    smsxml += "        <stat>"
    smsxml += sms['State']
    smsxml += "</stat>\n"

    smsxml += "    </message>\n"

    return smsxml

def SMSExportXML(parent, messages, contacts):
    count = len(messages)

# 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/Locales.py
# def ugettext(message):
#     if _TRANSLATION:
#         if six.PY2:
#             return _TRANSLATION.ugettext(message)
#         return _TRANSLATION.gettext(message)
#     return message


# Path: Wammu/SMSXML.py
from Wammu.Utils import SearchNumber
from Wammu.MessageDisplay import SmsTextFormat
from Wammu.Locales import ugettext as _
from xml.sax.saxutils import escape
import Wammu.Data
import wx
import os

        smsxml += "        <dateenc>"
        smsxml += sms['DateTime'].strftime("%Y%m%d%H%M%S")
        smsxml += "</dateenc>\n"

    smsxml += "        <text>"
    smsxml += escape(text.encode('utf-8'))
    smsxml += "</text>\n"

    smsxml += "        <telephone>"
    smsxml += escape(sms['Number'].encode('utf-8'))
    smsxml += "</telephone>\n"

    smsxml += "        <contact>"
    smsxml += escape(contact.encode('utf-8'))
    smsxml += "</contact>\n"

    smsxml += "        <folder>"
    smsxml += str(sms['Folder'])
    smsxml += "</folder>\n"

    smsxml += "        <stat>"
    smsxml += sms['State']
    smsxml += "</stat>\n"

    smsxml += "    </message>\n"

    return smsxml

def SMSExportXML(parent, messages, contacts):
    count = len(messages)

    wildcard = _('XML File') + ' (*.xml)|*.xml|' + _('All files') + ' (*.*)|*.*;*'