# 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
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
'''
Wammu - Phone manager
Module for writing SMS to XML.
'''


XMLheader = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\"sms.xsl\"?>\n'




def SMSToXML(cfg, sms, contact=None):
    '''
    Convert a sms to XML
    '''



# 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

#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <https://www.gnu.org/licenses/>.
'''
Wammu - Phone manager
Module for writing SMS to XML.
'''


XMLheader = '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\"sms.xsl\"?>\n'




def SMSToXML(cfg, sms, contact=None):
    '''
    Convert a sms to XML
    '''



    text = SmsTextFormat(cfg, sms['Text'], doxml=True)