Commit b7bd6612 authored by putro's avatar putro

added error management for unicode chars

parent 330cbf82
......@@ -48,6 +48,10 @@ remember to keep your stats & keys in your local mixmaster updated
TODO/PROBLEMS:
only ascii characters are managed for subject and messages, TODO: add unicode support
tested only with python 2.7
dependencies:
python-gnupg (https://bitbucket.org/vinay.sajip/python-gnupg)
......
......@@ -8,9 +8,9 @@ import traceback
import re
from stats import parse_stats, stats_m, uptime_sort_m, format_stats
from utils import pressKey, validateChoice, chooseList, askPassphrase, askSomething, askYesNo
from utils import chooseSubjType, selectServer, getDomain, validateEmail, isGpg
from utils import chooseSubjType, selectServer, getDomain, validateEmail, isGpg, isAscii
import gpgfuncts
import easygui
import easygui
import string
import subprocess
......@@ -147,10 +147,17 @@ def updateNym(delete=False):
pwd = askPassphrase()
else:
pwd = anym['passphrase']
if not delete:
subj_type = chooseSubjType(config)
subject = askSomething('Enter the subject you want to use with this nym: ')
while True:
subject = askSomething('Enter the subject you want to use with this nym: ')
if isAscii(subject):
break
else:
print "ERROR: subject contains not ascii characters, try again"
pressKey()
continue
configSection(anym.name, subject, subj_type)
writeConfig()
......@@ -160,6 +167,7 @@ def updateNym(delete=False):
subject = "yes"
msg = prepareSetupMsg(gpgfuncts.selectSecKey(anym.name), subj_type, subject)
emsg = signCryptMsg(msg, dest, sign=anym.fp, passphrase=pwd)
if not emsg:
config['last_message'] = "Something went wrong while preparing the message, recipient key missing ???"
......@@ -188,8 +196,14 @@ def deleteNymKeysConfig():
def prepareSetupMsg(keyid, subj_type, subject):
key = gpgfuncts.exportPubKey(keyid)
msg = "\n%s: %s\n\n" % (subj_type, subject) + key
return msg
try:
msg = "\n%s: %s\n\n" % (subj_type, subject) + key
return msg
except UnicodeDecodeError, e:
print 'Unicode Error: ', e.reason
print 'Please use only plain ascii characters'
pressKey()
menu()
def signCryptMsg(msg, dest, sign, passphrase):
......@@ -237,7 +251,16 @@ def writeMessage():
if anym.fp is False:
config['last_message'] = "ERROR - select your nym, actual selection HAS NOT a secret key"
menu()
subject = raw_input("Insert message subject: ")
while True:
subject = askSomething('Insert message subject: ')
if isAscii(subject):
break
else:
print "ERROR: subject contains not ascii characters, try again"
pressKey()
continue
recipient = raw_input("Insert recipient email address or newsgroup name: ")
......
......@@ -156,3 +156,6 @@ def isGpg(message):
return True
else:
return False
def isAscii(text):
return all(ord(c) < 128 for c in text)
......@@ -109,8 +109,8 @@ def val_n_copies(n_copies):
# Here we make the following design choices:
# - Do not allow the user to use a known bad chain
# - Do not allow the user to use a middleman remailer as last hop
# - Do not allow the user to use a remailer that does not support the
# post directive as last hop when posting to a newsgroup without a
# - Do not allow the user to use a remailer that does not support the
# post directive as last hop when posting to a newsgroup without a
# mail2news gateway.
# - Translate a choice of RANDOM to '*' (the mixmaster random chain)
# - Check for duplicate remailers.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment