xenoslib 0.1.29.13__tar.gz → 0.1.29.15__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.
Files changed (22) hide show
  1. {xenoslib-0.1.29.13/xenoslib.egg-info → xenoslib-0.1.29.15}/PKG-INFO +1 -1
  2. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib/about.py +1 -1
  3. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib/mail.py +31 -19
  4. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15/xenoslib.egg-info}/PKG-INFO +1 -1
  5. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/LICENSE +0 -0
  6. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/README.md +0 -0
  7. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/setup.cfg +0 -0
  8. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/setup.py +0 -0
  9. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib/__init__.py +0 -0
  10. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib/__main__.py +0 -0
  11. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib/base.py +0 -0
  12. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib/dev.py +0 -0
  13. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib/extend.py +0 -0
  14. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib/linux.py +0 -0
  15. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib/mock.py +0 -0
  16. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib/onedrive.py +0 -0
  17. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib/win_trayicon.py +0 -0
  18. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib/windows.py +0 -0
  19. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib.egg-info/SOURCES.txt +0 -0
  20. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib.egg-info/dependency_links.txt +0 -0
  21. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib.egg-info/requires.txt +0 -0
  22. {xenoslib-0.1.29.13 → xenoslib-0.1.29.15}/xenoslib.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xenoslib
3
- Version: 0.1.29.13
3
+ Version: 0.1.29.15
4
4
  Summary: Xenos' common lib
5
5
  Home-page: https://github.com/XenosLu/xenoslib.git
6
6
  Author: Xenocider
@@ -4,4 +4,4 @@ __url__ = "https://github.com/XenosLu/xenoslib.git"
4
4
  __author__ = "Xenocider"
5
5
  __author_email__ = "xenos.lu@gmail.com"
6
6
  __license__ = "MIT License"
7
- __version__ = "0.1.29.13"
7
+ __version__ = "0.1.29.15"
@@ -40,13 +40,14 @@ class MailFetcher:
40
40
  """
41
41
 
42
42
  def __new__(
43
- cls, imap_server, mail_addr, mail_pwd, interval=30, days=1, skip_current=True, endless=True
43
+ cls, imap_server, mail_addr, mail_pwd, interval=30, days=1, timeout=30, skip_current=True, endless=True
44
44
  ):
45
45
  self = super().__new__(cls)
46
46
  self.imap_server = imap_server
47
47
  self.mail_addr = mail_addr
48
48
  self.mail_pwd = mail_pwd
49
49
  self.days = days
50
+ self.timeout=timeout
50
51
 
51
52
  self.msg_ids = deque(maxlen=999)
52
53
  if not endless:
@@ -95,7 +96,7 @@ class MailFetcher:
95
96
  logger.debug(f"Fetching emails since {from_date:%Y-%m-%d %H:%M:%S} ({self.days} days ago)")
96
97
  for i in range(5):
97
98
  try:
98
- with IMAPClient(self.imap_server, timeout=30) as client:
99
+ with IMAPClient(self.imap_server, timeout=self.timeout) as client:
99
100
  client.login(self.mail_addr, self.mail_pwd)
100
101
  client.select_folder("INBOX", readonly=True)
101
102
  messages = client.search(["SINCE", from_date])
@@ -104,7 +105,7 @@ class MailFetcher:
104
105
  except Exception as exc:
105
106
  logger.warning(exc)
106
107
  sleep(30)
107
- raise Exception("Reached maximum retry attempts. Giving up connection.")
108
+ raise Exception("Reached maximum retry attempts when connect IMAP server. Giving up connection.")
108
109
 
109
110
 
110
111
  class SMTPMail:
@@ -127,24 +128,19 @@ class SMTPMail:
127
128
  receivers.append(receiver)
128
129
  elif isinstance(receiver, (list, tuple)):
129
130
  receivers.extend(receiver)
130
- msg = MIMEMultipart()
131
- msg["Subject"] = Header(subject, "utf-8")
132
- msg["From"] = Header(self.sender, "utf-8")
133
- msg["To"] = ";".join(receivers)
131
+ msg = self.construct_msg(
132
+ subject=subject,
133
+ message=message,
134
+ receivers=receivers,
135
+ cc=cc,
136
+ filename=filename,
137
+ )
134
138
  if cc:
135
139
  msg["Cc"] = ";".join(cc)
136
140
  receivers.extend(cc)
137
141
  if bcc:
138
142
  receivers.extend(bcc)
139
- msg["Message-ID"] = make_msgid()
140
- msg.attach(MIMEText(message, "html", "utf-8"))
141
- if filename:
142
- attachment = MIMEApplication(open(filename, "rb").read())
143
- attachment.add_header("Content-Disposition", "attachment", filename=filename)
144
- msg.attach(attachment)
145
-
146
143
  with self.SMTP(self.smtp_server, self.port) as smtp:
147
- print(smtp.has_extn("STARTTLS"))
148
144
  if smtp.has_extn("STARTTLS"):
149
145
  smtp.starttls()
150
146
  try:
@@ -155,6 +151,19 @@ class SMTPMail:
155
151
  smtp.sendmail(self.sender, receivers, msg.as_string())
156
152
  return True
157
153
 
154
+ def construct_msg(self, subject, message, receivers=None, cc=None, filename=None):
155
+ msg = MIMEMultipart()
156
+ msg["Subject"] = Header(subject, "utf-8")
157
+ msg["From"] = Header(self.sender, "utf-8")
158
+ msg["To"] = ";".join(receivers)
159
+ msg["Message-ID"] = make_msgid()
160
+ msg.attach(MIMEText(message, "html", "utf-8"))
161
+ if filename:
162
+ attachment = MIMEApplication(open(filename, "rb").read())
163
+ attachment.add_header("Content-Disposition", "attachment", filename=filename)
164
+ msg.attach(attachment)
165
+ return msg
166
+
158
167
 
159
168
  def test_imap():
160
169
  try:
@@ -173,7 +182,7 @@ def test_imap():
173
182
  # ~ print(email_data.keys())
174
183
 
175
184
 
176
- def test():
185
+ def test_smtp():
177
186
  try:
178
187
  import env # noqa
179
188
  except ModuleNotFoundError:
@@ -185,9 +194,12 @@ def test():
185
194
  message = '<span style="color:red">This is a test email.</span>'
186
195
  email_sender = SMTPMail(smtp_server, sender=mail_addr, password=mail_pwd, port=465)
187
196
  # email_sender = SMTPMail(smtp_server, sender=mail_addr, password=mail_pwd, port=587)
188
- email_sender.send(subject=subject, message=message, receiver=os.environ["RECEIVER"])
197
+ # ~ email_sender.send(subject=subject, message=message, receiver=os.environ["RECEIVER"],bcc=["haiwe.lu@sap.com"])
198
+ email_sender.send(
199
+ subject=subject, message=message, receiver="luhw@cndatacom.com", bcc=["haiwei.lu@sap.com"]
200
+ )
189
201
 
190
202
 
191
203
  if __name__ == "__main__":
192
- test_imap()
193
- # ~ test()
204
+ # ~ test_imap()
205
+ test_smtp()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: xenoslib
3
- Version: 0.1.29.13
3
+ Version: 0.1.29.15
4
4
  Summary: Xenos' common lib
5
5
  Home-page: https://github.com/XenosLu/xenoslib.git
6
6
  Author: Xenocider
File without changes
File without changes
File without changes
File without changes