pst: pass the command line ipath as base64 as there is no msw way to pass utf-8
This commit is contained in:
parent
6c73a0d666
commit
5d25094107
@ -82,17 +82,18 @@ class RclExecM:
|
|||||||
import msvcrt
|
import msvcrt
|
||||||
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
|
msvcrt.setmode(sys.stdout.fileno(), os.O_BINARY)
|
||||||
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
|
msvcrt.setmode(sys.stdin.fileno(), os.O_BINARY)
|
||||||
self.debugfile = None
|
self.debugfile = my_config.getConfParam("filterdebuglog")
|
||||||
if self.debugfile:
|
if self.debugfile:
|
||||||
self.errfout = open(self.debugfile, "a")
|
self.errfout = open(self.debugfile, "a")
|
||||||
else:
|
else:
|
||||||
self.errfout = sys.stderr
|
self.errfout = sys.stderr
|
||||||
|
|
||||||
def rclog(self, s, doexit = 0, exitvalue = 1):
|
def rclog(self, s, doexit = 0, exitvalue = 1):
|
||||||
# On windows, and I think that it changed quite recently (Qt change?)
|
# On windows, and I think that it changed quite recently (Qt change?)
|
||||||
# we get stdout as stderr. So don't write at all
|
# we get stdout as stderr. So don't write at all
|
||||||
if sys.platform != "win32":
|
if self.debugfile or sys.platform != "win32":
|
||||||
print("RCLMFILT: %s: %s" % (self.myname, s), file=self.errfout)
|
print("RCLMFILT: %s: %s" % (self.myname, s), file=self.errfout)
|
||||||
|
self.errfout.flush()
|
||||||
if doexit:
|
if doexit:
|
||||||
sys.exit(exitvalue)
|
sys.exit(exitvalue)
|
||||||
|
|
||||||
|
|||||||
@ -33,6 +33,7 @@ import subprocess
|
|||||||
import rclexecm
|
import rclexecm
|
||||||
import rclconfig
|
import rclconfig
|
||||||
import conftree
|
import conftree
|
||||||
|
import base64
|
||||||
|
|
||||||
_mswindows = (sys.platform == "win32" or sys.platform == "msys")
|
_mswindows = (sys.platform == "win32" or sys.platform == "msys")
|
||||||
if _mswindows:
|
if _mswindows:
|
||||||
@ -42,7 +43,10 @@ if _mswindows:
|
|||||||
met_splitext = ntpath.splitext
|
met_splitext = ntpath.splitext
|
||||||
met_join = ntpath.join
|
met_join = ntpath.join
|
||||||
def _backslashize(s):
|
def _backslashize(s):
|
||||||
return s.replace("/", "\\")
|
if type(s) == type(""):
|
||||||
|
return s.replace("/", "\\")
|
||||||
|
else:
|
||||||
|
return s.replace(b"/", b"\\")
|
||||||
else:
|
else:
|
||||||
met_basename = os.path.basename
|
met_basename = os.path.basename
|
||||||
met_dirname = os.path.dirname
|
met_dirname = os.path.dirname
|
||||||
@ -69,15 +73,17 @@ class EmailBuilder(object):
|
|||||||
self.attachments = []
|
self.attachments = []
|
||||||
|
|
||||||
def setheaders(self, h):
|
def setheaders(self, h):
|
||||||
|
#self.log("EmailBuilder: headers")
|
||||||
self.headers = h
|
self.headers = h
|
||||||
|
|
||||||
def setbody(self, body, main, sub):
|
def setbody(self, body, main, sub):
|
||||||
|
#self.log("EmailBuilder: body")
|
||||||
self.body = body
|
self.body = body
|
||||||
self.bodymimemain = main
|
self.bodymimemain = main
|
||||||
self.bodymimesub = sub
|
self.bodymimesub = sub
|
||||||
|
|
||||||
def addattachment(self, att, filename):
|
def addattachment(self, att, filename):
|
||||||
#self.log("Adding attachment")
|
#self.log("EmailBuilder: attachment")
|
||||||
self.attachments.append((att, filename))
|
self.attachments.append((att, filename))
|
||||||
|
|
||||||
def flush(self):
|
def flush(self):
|
||||||
@ -87,7 +93,7 @@ class EmailBuilder(object):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
newmsg = email.message.EmailMessage(policy=email.policy.default)
|
newmsg = email.message.EmailMessage(policy=email.policy.default)
|
||||||
headerstr = self.headers.decode('utf-8')
|
headerstr = self.headers.decode("UTF-8")
|
||||||
# print("%s" % headerstr)
|
# print("%s" % headerstr)
|
||||||
headers = self.parser.parsestr(headerstr, headersonly=True)
|
headers = self.parser.parsestr(headerstr, headersonly=True)
|
||||||
#self.log("EmailBuilder: content-type %s" % headers['content-type'])
|
#self.log("EmailBuilder: content-type %s" % headers['content-type'])
|
||||||
@ -177,7 +183,7 @@ class PFFReader(object):
|
|||||||
if name == "":
|
if name == "":
|
||||||
break
|
break
|
||||||
try:
|
try:
|
||||||
paramstr = data.decode('utf-8')
|
paramstr = data.decode("UTF-8")
|
||||||
except:
|
except:
|
||||||
paramstr = ''
|
paramstr = ''
|
||||||
|
|
||||||
@ -254,7 +260,10 @@ class PstExtractor(object):
|
|||||||
def startCmd(self, filename, ipath=None):
|
def startCmd(self, filename, ipath=None):
|
||||||
fullcmd = self.cmd
|
fullcmd = self.cmd
|
||||||
if ipath:
|
if ipath:
|
||||||
fullcmd += ["-p", ipath]
|
# There is no way to pass an utf-8 string on the command
|
||||||
|
# line on Windows. Use base64 encoding
|
||||||
|
bip = base64.b64encode(ipath.encode("UTF-8"))
|
||||||
|
fullcmd += ["-p", bip.decode("UTF-8")]
|
||||||
fn = _backslashize(rclexecm.subprocfile(filename))
|
fn = _backslashize(rclexecm.subprocfile(filename))
|
||||||
fullcmd += [fn,]
|
fullcmd += [fn,]
|
||||||
try:
|
try:
|
||||||
@ -265,6 +274,9 @@ class PstExtractor(object):
|
|||||||
except OSError as err:
|
except OSError as err:
|
||||||
self.em.rclog("Pst: Popen(%s) OS error: %s" % (fullcmd, err))
|
self.em.rclog("Pst: Popen(%s) OS error: %s" % (fullcmd, err))
|
||||||
return (False, "")
|
return (False, "")
|
||||||
|
except Exception as err:
|
||||||
|
self.em.rclog("Pst: Popen(%s) Exception: %s" % (fullcmd, err))
|
||||||
|
return (False, "")
|
||||||
self.filein = self.proc.stdout
|
self.filein = self.proc.stdout
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -291,8 +303,6 @@ class PstExtractor(object):
|
|||||||
self.em.setmimetype("message/rfc822")
|
self.em.setmimetype("message/rfc822")
|
||||||
self.em.rclog("getipath doc len %d [%s] ipath %s" %
|
self.em.rclog("getipath doc len %d [%s] ipath %s" %
|
||||||
(len(doc), doc[:20], ipath))
|
(len(doc), doc[:20], ipath))
|
||||||
f = open("/tmp/document", "wb")
|
|
||||||
f.write(doc.encode('utf-8'))
|
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
self.em.rclog("getipath: StopIteration")
|
self.em.rclog("getipath: StopIteration")
|
||||||
return(False, "", "", rclexecm.RclExecM.eofnow)
|
return(False, "", "", rclexecm.RclExecM.eofnow)
|
||||||
@ -325,8 +335,6 @@ if True:
|
|||||||
extract = PstExtractor(proto)
|
extract = PstExtractor(proto)
|
||||||
rclexecm.main(proto, extract)
|
rclexecm.main(proto, extract)
|
||||||
else:
|
else:
|
||||||
def _deb(s):
|
|
||||||
print("%s" % s, file=sys.stderr)
|
|
||||||
reader = PFFReader(_deb, infile=sys.stdin.buffer)
|
reader = PFFReader(_deb, infile=sys.stdin.buffer)
|
||||||
generator = reader.mainloop()
|
generator = reader.mainloop()
|
||||||
for doc, ipath in generator:
|
for doc, ipath in generator:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user