Skip to content

Commit

Permalink
added keyword to count emails by criteria
Browse files Browse the repository at this point in the history
  • Loading branch information
Antti Pakkanen committed Aug 21, 2020
1 parent c588ff6 commit 3eee4e9
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/ImapLibrary2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,9 @@ def walk_multipart_email(self, email_index):
# return number of parts
return len(self._mp_msg.get_payload())

def get_email_count(self, **kwargs):
return len(self._check_emails(**kwargs))

def _check_emails(self, **kwargs):
"""Returns filtered email."""
folder = '"%s"' % str(kwargs.pop('folder', self.FOLDER))
Expand All @@ -375,15 +378,15 @@ def _criteria(**kwargs):
criteria = []
recipient = kwargs.pop('recipient', kwargs.pop('to_email', kwargs.pop('toEmail', None)))
sender = kwargs.pop('sender', kwargs.pop('from_email', kwargs.pop('fromEmail', None)))
cc = kwargs.pop('cc', kwargs.pop('cc_email', kwargs.pop('ccEmail', None)))
cc = kwargs.pop('cc', kwargs.pop('cc_email', kwargs.pop('ccEmail', None)))
status = kwargs.pop('status', None)
subject = kwargs.pop('subject', None)
text = kwargs.pop('text', None)
if recipient:
criteria += ['TO', '"%s"' % recipient]
if sender:
criteria += ['FROM', '"%s"' % sender]
if cc:
if cc:
criteria += ['CC', '"%s"' % cc]
if subject:
criteria += ['SUBJECT', '"%s"' % subject]
Expand Down Expand Up @@ -415,5 +418,3 @@ def _get_all_emails(self):
"""Saves all existing emails to internal variable."""
typ, mails = self._imap.uid('search', None, 'ALL')
self._mails = mails[0].split()


0 comments on commit 3eee4e9

Please sign in to comment.