-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Various improvements to muttdown #5
Open
GrantEdwards
wants to merge
10
commits into
Roguelazer:master
Choose a base branch
from
GrantEdwards:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c72c5fe
Only remove the first sigil from text before processing with muttdown.
GrantEdwards 5d59e0b
Print any exception to stderr (will show up in mutt status line).
GrantEdwards d0825e7
Allow main.py to run standalone (without installing).
GrantEdwards 8e327e1
Make config file "option" optional.
GrantEdwards 2c137ca
Add markdown_extensions config option.
GrantEdwards 2c04630
Add support for !p sigil that uses 'pre' tags to enclose entire message
GrantEdwards 66fb402
If css option is used, enclose body in 'body' tags to improve rendering
GrantEdwards b770251
Wait for sendmail subprocess and return error if it fails.
GrantEdwards c6eea2b
Make it easier to run main.py without installing.
GrantEdwards d4a1324
Add 'utf8' config option that treats message text as UTF8, even if
GrantEdwards File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
#!/usr/bin/env python2 | ||
from __future__ import print_function | ||
|
||
import argparse | ||
|
@@ -16,32 +17,54 @@ | |
import markdown | ||
import pynliner | ||
|
||
from . import config | ||
from . import __version__ | ||
try: | ||
from . import config | ||
from . import __version__ | ||
__name__ = 'muttdown' | ||
except ValueError: | ||
import config | ||
__version__ = 'testing' | ||
|
||
__name__ = 'muttdown' | ||
def convert_markdown(text,config): | ||
return markdown.markdown(text,config.markdown_extensions,output_format="html5") | ||
|
||
def convert_preformat(text,config): | ||
import cgi | ||
return '<pre>\n' + cgi.escape(text) + '\n</pre>\n' | ||
|
||
def convert_one(part, config): | ||
try: | ||
text = part.get_payload(None, True) | ||
if not text.startswith('!m'): | ||
|
||
if text.startswith('!m'): | ||
converter = convert_markdown | ||
elif text.startswith('!p'): | ||
converter = convert_preformat | ||
else: | ||
return None | ||
text = re.sub('\s*!m\s*', '', text, re.M) | ||
text = re.sub('\s*![pm]\s*', '', text, count=1, flags=re.M) | ||
if config.remove_sigil: | ||
part.set_payload(text) | ||
if config.utf8: | ||
text = unicode(text,'utf8') | ||
if '\n-- \n' in text: | ||
pre_signature, signature = text.split('\n-- \n') | ||
md = markdown.markdown(pre_signature, output_format="html5") | ||
md = converter(pre_signature,config) | ||
md += '\n<div class="signature" style="font-size: small"><p>-- <br />' | ||
md += '<br />'.join(signature.split('\n')) | ||
md += '</p></div>' | ||
else: | ||
md = markdown.markdown(text) | ||
md = converter(text,config) | ||
if config.css: | ||
md = '<style>' + config.css + '</style>' + md | ||
md = '<style>\n' + config.css + '</style>\n' + '<body>\n' + md + '\n</body>\n' | ||
md = pynliner.fromString(md) | ||
message = MIMEText(md, 'html') | ||
if config.utf8: | ||
message = MIMEText(md.encode('utf-8'), 'html', _charset='utf-8') | ||
else: | ||
message = MIMEText(md, 'html') | ||
return message | ||
except Exception: | ||
except Exception as e: | ||
sys.stderr.write('muttdown: '+str(e)) | ||
return None | ||
|
||
|
||
|
@@ -116,7 +139,7 @@ def main(): | |
parser = argparse.ArgumentParser(version='%s %s' % (__name__, __version__)) | ||
parser.add_argument( | ||
'-c', '--config_file', default=os.path.expanduser('~/.muttdown.yaml'), | ||
type=argparse.FileType('r'), required=True, | ||
type=argparse.FileType('r'), required=False, | ||
help='Path to YAML config file (default %(default)s)' | ||
) | ||
parser.add_argument( | ||
|
@@ -153,6 +176,8 @@ def main(): | |
|
||
proc = subprocess.Popen(cmd, stdin=subprocess.PIPE, shell=False) | ||
proc.communicate(rebuilt.as_string()) | ||
proc.wait() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
sys.exit(proc.returncode) | ||
|
||
else: | ||
conn = smtp_connection(c) | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
newline here perhaps