PyEmailerAJM 1.0__tar.gz → 1.1__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.
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyEmailerAJM
3
- Version: 1.0
3
+ Version: 1.1
4
4
  Summary: Allows for automating sending Email with the Outlook Desktop client. Future releases will add more client support
5
5
  Home-page: https://github.com/amcsparron2793-Water/PyEmailer
6
6
  Author: Amcsparron
7
7
  Author-email: amcsparron@albanyny.gov
8
8
  License: MIT License
9
- Download-URL: https://github.com/amcsparron2793-Water/PyEmailer/archive/refs/tags/1.0.tar.gz
9
+ Download-URL: https://github.com/amcsparron2793-Water/PyEmailer/archive/refs/tags/1.1.tar.gz
10
10
  Keywords: Outlook,Email,Automation
11
11
  Platform: UNKNOWN
12
12
  License-File: LICENSE.txt
@@ -4,7 +4,7 @@ PyEmailerAJM.py
4
4
 
5
5
  install win32 with pip install pywin32
6
6
  """
7
- from os.path import isfile, abspath, isabs
7
+ from os.path import isfile, abspath, isabs, join
8
8
 
9
9
  # imports
10
10
 
@@ -41,14 +41,66 @@ class PyEmailer:
41
41
  self._recipient = None
42
42
  self._subject = None
43
43
  self._text = None
44
+ self.read_folder = None
44
45
 
45
46
  try:
46
47
  self.email_app = win32.Dispatch(self.email_app_name)
48
+ self._mapi_ns = self.email_app.GetNamespace('MAPI')
47
49
  self.email = self.email_app.CreateItem(0)
48
50
  except com_error as e:
49
51
  self._logger.error(e, exc_info=True)
50
52
  raise e
51
53
 
54
+ def _GetReadFolder(self, email_dir_index: int = 6):
55
+ # 6 = inbox
56
+ self.read_folder = self._mapi_ns.GetDefaultFolder(email_dir_index)
57
+ return self.read_folder
58
+
59
+ def GetMessages(self, folder_index=None):
60
+ if isinstance(folder_index, int):
61
+ self.read_folder = self._GetReadFolder(folder_index)
62
+ elif not folder_index and self.read_folder:
63
+ pass
64
+ elif not folder_index:
65
+ self.read_folder = self._GetReadFolder()
66
+ else:
67
+ try:
68
+ raise TypeError("folder_index must be an integer or self.read_folder must be defined")
69
+ except TypeError as e:
70
+ self._logger.error(e, exc_info=True)
71
+ raise e
72
+ return self.read_folder.Items
73
+
74
+ def GetEmailMessageBody(self, msg):
75
+ """message = messages.GetLast()"""
76
+ body_content = msg.body
77
+ if body_content:
78
+ return body_content
79
+ else:
80
+ try:
81
+ raise ValueError("This message has no body.")
82
+ except ValueError as e:
83
+ self._logger.error(e, exc_info=True)
84
+ raise e
85
+
86
+ def FindMsgBySubject(self, subject: str) -> list:
87
+ matched_messages = []
88
+ for message in self.GetMessages():
89
+ if message.Subject == subject:
90
+ matched_messages.append(message)
91
+ return matched_messages
92
+
93
+ def SaveAllEmailAttachments(self, msg, save_dir_path):
94
+ attachments = msg.Attachments
95
+ for attachment in attachments:
96
+ full_save_path = join(save_dir_path, str(attachment))
97
+ try:
98
+ attachment.SaveAsFile(full_save_path)
99
+ self._logger.debug(f"{full_save_path} saved from email with subject {msg.subject}")
100
+ except Exception as e:
101
+ self._logger.error(e, exc_info=True)
102
+ raise e
103
+
52
104
  def SetupEmail(self, recipient: str, subject: str, text: str, attachments: list = None):
53
105
  def _validate_attachments():
54
106
  if attachments:
@@ -1,12 +1,12 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: PyEmailerAJM
3
- Version: 1.0
3
+ Version: 1.1
4
4
  Summary: Allows for automating sending Email with the Outlook Desktop client. Future releases will add more client support
5
5
  Home-page: https://github.com/amcsparron2793-Water/PyEmailer
6
6
  Author: Amcsparron
7
7
  Author-email: amcsparron@albanyny.gov
8
8
  License: MIT License
9
- Download-URL: https://github.com/amcsparron2793-Water/PyEmailer/archive/refs/tags/1.0.tar.gz
9
+ Download-URL: https://github.com/amcsparron2793-Water/PyEmailer/archive/refs/tags/1.1.tar.gz
10
10
  Keywords: Outlook,Email,Automation
11
11
  Platform: UNKNOWN
12
12
  License-File: LICENSE.txt
@@ -2,10 +2,10 @@ from setuptools import setup
2
2
 
3
3
  setup(
4
4
  name='PyEmailerAJM',
5
- version='1.0',
5
+ version='1.1',
6
6
  packages=['PyEmailerAJM'],
7
7
  url='https://github.com/amcsparron2793-Water/PyEmailer',
8
- download_url='https://github.com/amcsparron2793-Water/PyEmailer/archive/refs/tags/1.0.tar.gz',
8
+ download_url='https://github.com/amcsparron2793-Water/PyEmailer/archive/refs/tags/1.1.tar.gz',
9
9
  keywords=["Outlook", "Email", "Automation"],
10
10
  install_requires=['pywin32'],
11
11
  license='MIT License',
File without changes
File without changes
File without changes