From 17660220fe7c27f8c177974ff761eaf9b987a072 Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Sun, 13 Nov 2016 12:27:15 -0800 Subject: [PATCH] Added html argument to gam add sendas/update sendas/signature to control newline (NL) processing when signature is read from a file. (#331) --- src/GamCommands.txt | 6 +++--- src/gam.py | 37 +++++++++++++++++++++++++------------ 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/GamCommands.txt b/src/GamCommands.txt index 77aca339..4acbd4ef 100644 --- a/src/GamCommands.txt +++ b/src/GamCommands.txt @@ -792,14 +792,14 @@ gam show imap|imap4 gam pop|pop3 [for allmail|newmail|mailfromnowon|fromnowown] [action keep|leaveininbox|archive|delete|trash|markread] gam show pop|pop3 -gam [add] sendas [signature|sig |(file [charset ]) (replace )*] [replyto ] [default] [treatasalias ] -gam update sendas [name ] [signature|sig |(file [charset ]) (replace )*] [replyto ] [default] [treatasalias ] +gam [add] sendas [signature|sig |(file [charset ]) (replace )*] [html] [replyto ] [default] [treatasalias ] +gam update sendas [name ] [signature|sig |(file [charset ]) (replace )*] [html] [replyto ] [default] [treatasalias ] gam delete sendas gam show sendas [format] gam info sendas [format] gam print sendas [todrive] -gam signature|sig |(file [charset ]) (replace )* [name ] [replyto ] [default] [treatasalias ] +gam signature|sig |(file [charset ]) (replace )* [html] [name ] [replyto ] [default] [treatasalias ] gam show signature|sig [format] gam vacation diff --git a/src/gam.py b/src/gam.py index 542da0b4..2c43f469 100755 --- a/src/gam.py +++ b/src/gam.py @@ -5061,6 +5061,7 @@ def addUpdateSendAs(users, i, addCmd): body = {} signature = None tagReplacements = {} + html = False while i < len(sys.argv): myarg = sys.argv[i].lower() if myarg in [u'signature', u'sig']: @@ -5069,16 +5070,21 @@ def addUpdateSendAs(users, i, addCmd): if signature == u'file': filename = sys.argv[i] i, encoding = getCharSet(i+1) - signature = readFile(filename, encoding=encoding) + signature = readFile(filename, encoding=encoding).replace(u'\\n', u'
') + else: + signature = signature.replace(u'\\n', u'
') + elif myarg == u'html': + html = True + i += 1 else: i = getSendAsAttributes(i, myarg, body, tagReplacements, command) if signature is not None: - if not signature: - body[u'signature'] = None - elif tagReplacements: - body[u'signature'] = _processTags(tagReplacements, signature) - else: - body[u'signature'] = signature + if signature: + if tagReplacements: + signature = _processTags(tagReplacements, signature) + if not html: + signature = signature.replace(u'\n', u'
') + body[u'signature'] = signature kwargs = {u'body': body} if not addCmd: kwargs[u'sendAsEmail'] = emailAddress @@ -6107,13 +6113,20 @@ def doSignature(users): signature = getString(i, u'String', emptyOK=True).replace(u'\\n', u'
') i += 1 body = {} + html = False while i < len(sys.argv): myarg = sys.argv[i].lower() - i = getSendAsAttributes(i, myarg, body, tagReplacements, u'signature') - if tagReplacements: - body[u'signature'] = _processTags(tagReplacements, signature) - else: - body[u'signature'] = signature + if myarg == u'html': + html = True + i += 1 + else: + i = getSendAsAttributes(i, myarg, body, tagReplacements, u'signature') + if signature: + if tagReplacements: + signature = _processTags(tagReplacements, signature) + if not html: + signature = signature.replace(u'\n', u'
') + body[u'signature'] = signature i = 0 count = len(users) for user in users: