imap-archiver/iarchiver/email.py

18 lines
540 B
Python

import re
from datetime import datetime, timedelta
from typing import Union
def extract_emails(field: str):
matches = re.findall(r'([a-zA-Z0-9+._-]+@[a-zA-Z0-9._-]+\.[a-zA-Z0-9_-]+)', field.lower())
return tuple({str(x) for x in matches})
def unix_timestamp_since_to_imap_timestamp(unix_timestamp: Union[int, float]) -> str:
return (datetime.fromtimestamp(unix_timestamp) - timedelta(days=1)).strftime("%d-%b-%Y")
def normalize_for_imap_folder(folder: str):
folder = folder.replace("'", "\'")
return f'"{folder}"'