markdown-merge 0.1.4__tar.gz → 0.1.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of markdown-merge might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: markdown_merge
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: Send email using markdown
5
5
  Home-page: https://github.com/AnswerDotAI/markdown_merge
6
6
  Author: Jeremy Howard
@@ -0,0 +1,2 @@
1
+ __version__ = "0.1.5"
2
+ from .core import *
@@ -12,11 +12,13 @@ from fastcore.utils import *
12
12
  from email.mime.multipart import MIMEMultipart
13
13
  from email.mime.text import MIMEText
14
14
  from email.mime.base import MIMEBase
15
+ from email.policy import EmailPolicy
15
16
  from email import encoders
16
17
 
17
18
  from contextlib import contextmanager
18
19
  from markdown import markdown
19
20
  from email.headerregistry import Address
21
+ from email.header import Header
20
22
  from time import sleep
21
23
 
22
24
  # %% ../nbs/00_core.ipynb
@@ -38,7 +40,7 @@ def attach_file(msg, f):
38
40
  # %% ../nbs/00_core.ipynb
39
41
  def create_multipart_msg(subj, from_addr, to_addrs, md=None, html=None, attach=None):
40
42
  "Create a multipart email with markdown text and HTML"
41
- msg = MIMEMultipart('alternative')
43
+ msg = MIMEMultipart('alternative', policy=EmailPolicy())
42
44
  msg['Subject'],msg['From'] = subj,str(from_addr)
43
45
  msg['To'] = ', '.join([str(a) for a in listify(to_addrs)])
44
46
  if md: msg.attach(MIMEText(md, 'plain'))
@@ -53,14 +55,12 @@ def md2email(subj, from_addr, to_addrs, md, attach=None):
53
55
  return create_multipart_msg(subj, from_addr, to_addrs, md=md, html=html, attach=attach)
54
56
 
55
57
  # %% ../nbs/00_core.ipynb
56
- @contextmanager
57
58
  def smtp_connection(host, port, user=None, password=None, use_ssl=True, use_tls=False):
58
- "Context manager for SMTP connection"
59
+ "Create and return an SMTP connection"
59
60
  conn = smtplib.SMTP_SSL(host, port) if use_ssl else smtplib.SMTP(host, port)
60
61
  if use_tls and not use_ssl: conn.starttls()
61
62
  if user and password: conn.login(user, password)
62
- try: yield conn
63
- finally: conn.quit()
63
+ return conn
64
64
 
65
65
  # %% ../nbs/00_core.ipynb
66
66
  class MarkdownMerge:
@@ -70,16 +70,22 @@ class MarkdownMerge:
70
70
  self.inserts = [{}]*len(addrs) if inserts is None else inserts
71
71
  self.smtp_cfg,self.test = smtp_cfg,test
72
72
 
73
- def send_msgs(self, pause=0.5):
73
+ def send_msgs(self, pause=0.2):
74
74
  "Send all unsent messages to `addrs` with `pause` secs between each send"
75
- with smtp_connection(**self.smtp_cfg) as conn:
76
- while self.i < len(self.addrs):
77
- addr,insert = self.addrs[self.i],self.inserts[self.i]
78
- msg = self.msg.format(**insert)
79
- eml = md2email(self.subj, self.from_addr, addr, md=msg)
80
- if self.test: print(f"To: {addr}\n{'-'*40}\n{msg}\n{'='*40}\n")
81
- else: conn.send_message(eml); sleep(pause)
82
- self.i += 1
83
- if self.i%100==0: print(self.i)
75
+ conn = smtp_connection(**self.smtp_cfg)
76
+ while self.i < len(self.addrs):
77
+ addr,insert = self.addrs[self.i],self.inserts[self.i]
78
+ msg = self.msg.format(**insert)
79
+ eml = md2email(self.subj, self.from_addr, addr, md=msg)
80
+ if self.test: print(f"To: {addr}\n{'-'*40}\n{msg}\n{'='*40}\n")
81
+ else:
82
+ conn.send_message(eml)
83
+ sleep(pause)
84
+ self.i += 1
85
+ if self.i%100==0:
86
+ print(self.i)
87
+ conn.quit()
88
+ conn = smtp_connection(**self.smtp_cfg)
89
+ conn.quit()
84
90
 
85
91
  def reset(self): self.i=0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: markdown_merge
3
- Version: 0.1.4
3
+ Version: 0.1.5
4
4
  Summary: Send email using markdown
5
5
  Home-page: https://github.com/AnswerDotAI/markdown_merge
6
6
  Author: Jeremy Howard
@@ -1,7 +1,7 @@
1
1
  [DEFAULT]
2
2
  repo = markdown_merge
3
3
  lib_name = markdown_merge
4
- version = 0.1.4
4
+ version = 0.1.5
5
5
  min_python = 3.10
6
6
  license = apache2
7
7
  black_formatting = False
@@ -1,2 +0,0 @@
1
- __version__ = "0.1.4"
2
- from .core import *
File without changes
File without changes
File without changes
File without changes