### Install mail-parser Source: https://github.com/spamscope/mail-parser/blob/develop/README.md Installs the mail-parser library using pip. Includes optional verification and development setup instructions. ```bash pip install mail-parser ``` ```bash pip show mail-parser ``` ```bash git clone https://github.com/SpamScope/mail-parser.git cd mail-parser uv sync ``` -------------------------------- ### Start Docker Compose Services Source: https://github.com/spamscope/mail-parser/blob/develop/README.md This snippet shows the command to start the SpamScope Mail Parser services using Docker Compose. Ensure you are in the directory containing the `docker-compose.yml` file. This command builds and starts the containers defined in the file. ```shell sudo docker-compose up ``` -------------------------------- ### View Package Details Source: https://github.com/spamscope/mail-parser/blob/develop/README.md Retrieve detailed information about the installed Perl package for Outlook message parsing. ```bash apt-cache show libemail-outlook-message-perl ``` -------------------------------- ### Docker Compose Configuration Source: https://github.com/spamscope/mail-parser/blob/develop/README.md This is an example of a `docker-compose.yml` file for the SpamScope Mail Parser. It configures services, including mounting local directories (like `~/mails`) into the container and running test commands to verify functionality. ```yaml version: '3.8' services: mail-parser: build: . volumes: - ~/mails:/mails:ro command: ./run_test.sh /mails ``` -------------------------------- ### Install Outlook Message Parsing Dependency Source: https://github.com/spamscope/mail-parser/blob/develop/README.md On Debian-based systems, install the necessary Perl package to enable parsing of Outlook .msg email formats with mail-parser. ```bash apt-get install libemail-outlook-message-perl ``` -------------------------------- ### Running Docker Image Source: https://github.com/spamscope/mail-parser/blob/develop/README.md Provides the command to run the spamscope/mail-parser Docker image, including volume mounting for persistent access to mail files. ```Shell sudo docker run -it --rm -v ~/mails:/mails fmantuano/spamscope-mail-parser ``` -------------------------------- ### MailParser Python Module Usage Source: https://github.com/spamscope/mail-parser/blob/develop/README.md Demonstrates how to import the mailparser library and use its various parsing functions to process email data from different sources like bytes, files, strings, or file objects. It also shows how to access parsed email components and write attachments. ```APIDOC MailParser Module Usage: Import: import mailparser Parsing Methods: parse_from_bytes(byte_mail): Parses email content from a byte string. parse_from_file(f): Parses email content from a file object. parse_from_file_msg(outlook_mail): Parses email content from an Outlook .msg file. parse_from_file_obj(fp): Parses email content from a file-like object. parse_from_string(raw_mail): Parses email content from a raw string. Accessing Parsed Data: mail.attachments: list of all attachments. mail.body: The main body of the email. mail.date: datetime object in UTC representing the email date. mail.defects: List of RFC non-compliance defects found. mail.defects_categories: List of categories for the defects. mail.delivered_to: The 'Delivered-To' header value. mail.from_: The 'From' header value. mail.get_server_ipaddress(trust="my_server_mail_trust"): Attempts to get the server IP address. mail.headers: Dictionary of all email headers. mail.mail: Tokenized mail content as an object. mail.message: The raw email.message.Message object. mail.message_as_string: The raw email message as a string. mail.message_id: The 'Message-ID' header value. mail.received: List of 'Received' header entries. mail.subject: The 'Subject' header value. mail.text_plain: List of plain text parts of the email. mail.text_html: List of HTML parts of the email. mail.text_not_managed: List of text parts with unmanaged content subtypes. mail.to: List of 'To' header recipients. mail.to_domains: List of domains from 'To' header recipients. mail.timezone: The timezone of the email, as an offset from UTC. mail.mail_partial: Returns only the main parts of the email. Writing Attachments: mail.write_attachments(base_path): Writes all attachments to the specified directory path. ``` -------------------------------- ### Bitcoin Address for Donations Source: https://github.com/spamscope/mail-parser/blob/develop/README.md Contribute to the development of mail-parser using Bitcoin. This snippet displays the project's Bitcoin address and an associated image for easy donation. ```html Bitcoin **Bitcoin Address:** `bc1qxhz3tghztpjqdt7atey68s344wvmugtl55tm32` ``` -------------------------------- ### MailParser Command-Line Interface Source: https://github.com/spamscope/mail-parser/blob/develop/README.md Details the command-line usage of the mailparser tool, including options for specifying input (file, string, stdin), controlling output (JSON, body, attachments, headers), setting log levels, and handling specific parsing scenarios like Outlook messages or sender IP extraction. ```APIDOC MailParser CLI Usage: Signature: usage: mailparser [-h] [-f FILE | -s STRING | -k] [-l {CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET}] [-j] [-b] [-a] [-r] [-t] [-dt] [-m] [-u] [-c] [-d] [-o] [-i Trust mail server string] [-p] [-z] [-sa] [-ap ATTACHMENTS_PATH] [-v] Description: Wrapper for the email Python Standard Library to parse raw emails. Optional Arguments: -h, --help Show this help message and exit. -f FILE, --file FILE Specify a raw email file for parsing. -s STRING, --string STRING Specify a raw email string for parsing. -k, --stdin Enable parsing from standard input. -l {CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET}, --log-level {CRITICAL,ERROR,WARNING,INFO,DEBUG,NOTSET} Set the logging level (default: WARNING). -j, --json Output the parsed mail in JSON format. -b, --body Print the body of the mail. -a, --attachments Print information about attachments. -r, --headers Print the email headers. -t, --to Print the 'To' recipients. -dt, --delivered-to Print the 'Delivered-To' header. -m, --from Print the 'From' sender. -u, --subject Print the 'Subject' of the mail. -c, --receiveds Print all 'Received' headers. -d, --defects Print any parsing defects found. -o, --outlook Analyze Outlook .msg files. -i Trust mail server string, --senderip Trust mail server string Extract a reliable sender IP address heuristically. -p, --mail-hash Print mail fingerprints without headers. -z, --attachments-hash Print attachments with fingerprints. -sa, --store-attachments Store attachments on disk. -ap ATTACHMENTS_PATH, --attachments-path ATTACHMENTS_PATH Path where attachments should be stored (default: /tmp). -v, --version Show program's version number and exit. Example: mailparser -f example_mail -j This command parses 'example_mail' and outputs the result as JSON. ``` -------------------------------- ### MailParser Exception Hierarchy Source: https://github.com/spamscope/mail-parser/blob/develop/README.md Outlines the exception hierarchy for the mailparser library, detailing the base exception and specific error types raised during parsing operations. ```APIDOC MailParser Exception Hierarchy: MailParserError: Base MailParser Exception. - MailParserOutlookError: Raised with Outlook integration errors. - MailParserEnvironmentError: Raised when the environment is not correct. - MailParserOSError: Raised when an OS error occurs. - MailParserReceivedParsingError: Raised when a 'Received' header cannot be parsed. ``` -------------------------------- ### Mail Object Property Access Source: https://github.com/spamscope/mail-parser/blob/develop/README.md Demonstrates how to access various email properties from a parsed mail object. Properties can be accessed as native Python objects, JSON strings, or raw header strings. Custom headers require replacing hyphens with underscores. ```APIDOC Mail Object Properties: Accessing Standard Headers: - mail. (e.g., mail.to, mail.from_, mail.subject, mail.date) - Retrieves the header value as a native Python object. - mail._json (e.g., mail.to_json) - Retrieves the header value as a JSON string. - mail._raw (e.g., mail.to_raw) - Retrieves the header value as its raw string representation. Common Header Properties: - bcc - cc - date - delivered_to - from_ (Note: 'from' is a Python keyword) - message_id - received - reply_to - subject - to Accessing Other Components: - mail.body (The main email body content) - mail.body_html (The HTML part of the email body) - mail.body_plain (The plain text part of the email body) - mail.headers (All raw headers) - mail.attachments (List of attachment objects) - mail.sender_ip_address - mail.to_domains - mail.timezone Accessing Custom Headers: - To access custom headers (e.g., 'X-MSMail-Priority'), replace hyphens with underscores. - Example: mail.X_MSMail_Priority Defects: - mail.defects - Accesses a list of defects found in the email, indicating non-compliance with RFC standards. - Example: mail.defects Attachment Structure: - Each item in mail.attachments is an object with the following keys: - binary: boolean (true if binary attachment) - charset: string - content_transfer_encoding: string - content_disposition: string - content_id: string - filename: string - mail_content_type: string - payload: string (base64 encoded attachment payload) Received Header Structure: - The 'received' header is parsed into hops, each with fields like: - by: string - date: string - date_utc: string - delay: string (time between hops) - envelope_from: string - envelope_sender: string - for: string - from: string - hop: integer - with: string Usage Example: # Assuming 'mail' is a parsed mail object print(mail.subject) print(mail.body_plain) print(mail.attachments[0]['filename']) print(mail.X_MSMail_Priority_json) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.