parsedmarc.utils
🔗
Utility functions that might be useful for other projects
DownloadError
🔗
Bases: RuntimeError
Raised when an error occurs when downloading a file
EmailParserError
🔗
Bases: RuntimeError
Raised when an error parsing the email occurs
MboxIterator
🔗
MboxIterator(path: str)
Class that allows iterating through all messages in an mbox file
Returns tuples of (message_key, message)
.
convert_outlook_msg
🔗
decode_base64
🔗
extract_xml
🔗
get_base_domain
🔗
get_filename_safe_string
🔗
get_ip_address_country
🔗
Get the ISO code for the country associated with the given IPv4 or IPv6 address
PARAMETER | DESCRIPTION |
---|---|
ip_address |
The IP address to query for
TYPE:
|
db_path |
Path to a MMDB file from MaxMind or DBIP
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str | None
|
And ISO country code associated with the given IP address |
get_ip_address_info
🔗
get_ip_address_info(
ip_address: str,
ip_db_path: str | None = None,
cache: ExpiringDict | None = None,
offline: bool = False,
nameservers: list[str] | None = None,
timeout: float = 2.0,
) -> dict[str, Any]
Get reverse DNS and country information for the given IP address
PARAMETER | DESCRIPTION |
---|---|
ip_address |
The IP address to check
TYPE:
|
ip_db_path |
path to a MMDB file from MaxMind or DBIP
TYPE:
|
cache |
Cache storage
TYPE:
|
offline |
Do not make online queries for geolocation or DNS
TYPE:
|
nameservers |
A list of one or more nameservers to use (Cloudflare's public DNS resolvers by default) |
timeout |
Sets the DNS timeout in seconds
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
dict[str, Any]
|
Dictionary of ( |
get_reverse_dns
🔗
get_reverse_dns(
ip_address: str,
cache: ExpiringDict | None = None,
nameservers: list[str] | None = None,
timeout: float = 2.0,
) -> str | None
Resolve an IP address to a hostname using a reverse DNS query
PARAMETER | DESCRIPTION |
---|---|
ip_address |
The IP address to resolve
TYPE:
|
cache |
Cache storage
TYPE:
|
nameservers |
A list of one or more nameservers to use (Cloudflare's public DNS resolvers by default) |
timeout |
Sets the DNS query timeout in seconds
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
str | None
|
The reverse DNS hostname (if any) |
human_timestamp_to_datetime
🔗
human_timestamp_to_timestamp
🔗
is_mbox
🔗
Checks if the given content is an MBOX mailbox file
RETURNS | DESCRIPTION |
---|---|
bool
|
If the file is an MBOX mailbox file |
is_outlook_msg
🔗
load_bytes_from_source
🔗
parse_email
🔗
parse_email_address
🔗
Parse an email into parts
query_dns
🔗
query_dns(
domain: str,
record_type: str,
cache: ExpiringDict | None = None,
nameservers: list[str] | None = None,
timeout: float = 2.0,
) -> list[str]
Make a DNS query
PARAMETER | DESCRIPTION |
---|---|
domain |
The domain or subdomain to query about
TYPE:
|
record_type |
The record type to query for
TYPE:
|
cache |
Cache storage
TYPE:
|
nameservers |
A list of one or more nameservers to use (Cloudflare's public DNS resolvers by default) |
timeout |
Sets the DNS timeout in seconds
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
list[str]
|
A list of answers |