/usr/lib/python2.7/dist-packages/Wammu/MessageDisplay.py is in wammu 0.44-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 | # -*- coding: UTF-8 -*-
#
# Copyright © 2003 - 2018 Michal Čihař <michal@cihar.com>
#
# This file is part of Wammu <https://wammu.eu/>
#
# 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
Message to HTML conversion
'''
import Wammu
import Wammu.Data
import Wammu.Ringtone
import string
import re
import xml.sax.saxutils
from Wammu.Locales import UnicodeConv, HtmlStrConv, ugettext as _
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', ' ')
def SmsToHtml(cfg, v):
if 'SMSInfo' in v:
text = ''
ringno = 0
Wammu.Ringtone.ringtones = {}
for i in v['SMSInfo']['Entries']:
if i['ID'] in Wammu.Data.SMSIDs['PredefinedAnimation']:
if i['Number'] > len(Wammu.Data.PredefinedAnimations):
text = text + \
'<wxp module="Wammu.Image" class="Bitmap">' + \
'<param name="tooltip" value="' + (_('Predefined animation number %d') % i['Number']) + '">' + \
'<param name="image" value="' + "['" + string.join(Wammu.Data.UnknownPredefined, "', '") + "']" + '">' + \
'</wxp>'
else:
text = text + \
'<wxp module="Wammu.Image" class="Bitmap">' + \
'<param name="tooltip" value="' + Wammu.Data.PredefinedAnimations[i['Number']][0] + '">' + \
'<param name="image" value="' + "['" + string.join(Wammu.Data.PredefinedAnimations[i['Number']][1], "', '") + "']" + '">' + \
'</wxp>'
if i['ID'] in Wammu.Data.SMSIDs['PredefinedSound']:
if i['Number'] >= len(Wammu.Data.PredefinedSounds):
desc = _('Unknown predefined sound #%d') % i['Number']
else:
desc = Wammu.Data.PredefinedSounds[i['Number']][0]
text = text + \
'[<wxp module="Wammu.Image" class="Bitmap">' + \
'<param name="image" value="' + "['" + string.join(Wammu.Data.Note, "', '") + "']" + '">' + \
'</wxp>' + desc + ']'
if i['ID'] in Wammu.Data.SMSIDs['Sound']:
Wammu.Ringtone.ringtones[ringno] = i['Ringtone']
text = text + \
'<wxp module="Wammu.Ringtone" class="Ringtone">' + \
'<param name="tooltip" value="' + i['Ringtone']['Name'] + '">' + \
'<param name="ringno" value="' + str(ringno) + '">' + \
'</wxp>'
ringno += 1
if i['ID'] in Wammu.Data.SMSIDs['Text']:
fmt = '%s'
for x in Wammu.Data.TextFormats:
for name, txt, style in x[1:]:
if name in i and i[name]:
fmt = style % fmt
text = text + (fmt % SmsTextFormat(cfg, i['Buffer']))
if i['ID'] in Wammu.Data.SMSIDs['Bitmap']:
x = i['Bitmap'][0]
text = text + \
'<wxp module="Wammu.Image" class="Bitmap">' + \
'<param name="scale" value="(' + str(cfg.ReadInt('/Message/ScaleImage')) + ')">' + \
'<param name="image" value="' + "['" + string.join(x['XPM'], "', '") + "']" + '">' + \
'</wxp>'
if i['ID'] in Wammu.Data.SMSIDs['Animation']:
data = []
for x in i['Bitmap']:
data.append("['" + string.join(x['XPM'], "', '") + "']")
text = text + \
'<wxp module="Wammu.Image" class="Throbber">' + \
'<param name="scale" value="(' + str(cfg.ReadInt('/Message/ScaleImage')) + ')">' + \
'<param name="images" value="' + "[" + string.join(data, ", ") + "]" + '">' + \
'</wxp>'
if 'Unknown' in v['SMSInfo'] and v['SMSInfo']['Unknown']:
text = ('<table border="1" bgcolor="#dd7777" color="#000000"><tr><td>%s</td></tr></table>' % _('Some parts of this message were not decoded correctly, probably due to missing support for it in Gammu.')) + text
else:
text = SmsTextFormat(cfg, v['Text'])
return HtmlStrConv(text)
|