Skip to content

Commit

Permalink
mypy compatible components
Browse files Browse the repository at this point in the history
  • Loading branch information
aidencullo committed May 5, 2024
1 parent 1e93f69 commit 4cdfb17
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 18 deletions.
2 changes: 1 addition & 1 deletion conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from pathlib import Path
from unittest.mock import Mock, patch
from unittest.mock import Mock

import pytest

Expand Down
4 changes: 2 additions & 2 deletions src/nomail/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

from .action import ActionNone
from .email_filter import ListFilter
from .session import noop
from .session import run

__version__ = version("nomail")


def filter(rate_limit: int = 1):
blacklist = get_blacklist()
emails = session.run(ActionNone(), ListFilter(blacklist), rate_limit)
emails = run(ActionNone(), ListFilter(blacklist), rate_limit)
print_summary(emails)


Expand Down
2 changes: 1 addition & 1 deletion src/nomail/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import pandas as pd

from . import descriptor, sanitize
from . import sanitize


class Email:
Expand Down
4 changes: 2 additions & 2 deletions src/nomail/email_filter.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import List
from typing import List, Optional

from .email import Email


class ListFilter():
def __init__(self, address_list: List[str] = None):
def __init__(self, address_list: Optional[List[str]] = None):
if address_list is None:
address_list = []
self._address_list = address_list
Expand Down
13 changes: 7 additions & 6 deletions src/nomail/imap.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import email
import imaplib
from typing import List, Optional
from typing import List
from email.message import Message

from .env import CREDENTIALS, PROVIDER
from .util import split_bytes
Expand All @@ -11,7 +12,7 @@ class Imap():
def __init__(self):
try:
self._imap = imaplib.IMAP4_SSL(PROVIDER)
except ConnectionRefusedError as e:
except ConnectionRefusedError:
print("couldn't connect to imap email server")
print("this is most likely due to incorrect credentials, check your env file")
return
Expand All @@ -22,16 +23,16 @@ def __init__(self):
self._imap.login(*CREDENTIALS)
self._imap.select()

def get_msgs(self) -> List[str]:
def get_msgs(self) -> List[Message]:
return [self.get_msg_data(uid) for uid in self.get_uids()]

def get_msg_data(self, uid: int) -> str:
def get_msg_data(self, uid: bytes) -> Message:
return email.message_from_bytes(self.fetch_msg_from_server(uid))

def fetch_msg_from_server(self, uid: int) -> bytes:
def fetch_msg_from_server(self, uid: bytes) -> bytes:
return self._imap.fetch(uid, "(RFC822)")[1][0][1]

def get_uids(self) -> List[int]:
def get_uids(self) -> List[bytes]:
return split_bytes(self.fetch_uids_from_server())

def fetch_uids_from_server(self) -> bytes:
Expand Down
1 change: 0 additions & 1 deletion src/nomail/session.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import Optional

from .action import Action
from .adapter import EmailImapAdapter
Expand Down
7 changes: 5 additions & 2 deletions src/nomail/util.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
def split_bytes(byte_str: bytes) -> list[bytes]:
from typing import List


def split_bytes(byte_str: bytes) -> List[bytes]:
return byte_str.split(b' ') if byte_str else []


def to_int(collection):
def to_int(collection) -> List[int]:
return [int(item) for item in collection]
2 changes: 1 addition & 1 deletion tests/unit/email_filter_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import pytest

from nomail.email_filter import ListFilter
from nomail.filter import EmailFilterList


def email_mock_factory(sender):
Expand Down
3 changes: 1 addition & 2 deletions tests/unit/email_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from datetime import datetime
from unittest.mock import patch

import pandas as pd

from nomail.email import Email, EmailList
from nomail.email import Email


@patch("nomail.email.sanitize")
Expand Down

0 comments on commit 4cdfb17

Please sign in to comment.