Skip to main content

llama-index readers imap integration

Project description

LlamaIndex Readers Integration: IMAP

Overview

Simple IMAP reader allows loading emails from a given mailbox. It concatenates useful fields from each email into a single document used by LlamaIndex.

Installation

pip install llama-index-readers-imap

Usage

from llama_index.readers.imap import ImapReader

# Initialize the server
mailbox = ImapReader(
    host="<MAIL HOST>",
    username="<MAIL USERNAME>",
    password="<MAIL PASSWORD>",
)

# Lazy load emails from the given mailbox
emails = mailbox.lazy_load_data(
    folder="INBOX",  # Customize the folder to read from
    metadata_names=[
        "uid",
        "from_values",
    ],  # Customize the metadata (date is always included). You can get the full list at https://pypi.org/project/imap-tools/#email-attributes
    search_criteria=None,  # By default all emails are read, customize the query following https://pypi.org/project/imap-tools/#search-criteria
    save_attachment=None,  # Callback function to save attachments
)

Saving attachments

The lazy_load_data function accepts an optional save_attachment callback function which, if defined, is called for every attachment in the email.

Its only parameter is an imap_tools.MailAttachment which is described in the official documentation. It must return the path of the saved attachment as a string. Every saved attachment will be added to the Document metadata with its saved filename and the original one.

Here's a simple example of the save_attachment function:

import imap_tools


def save_attachment(attachment: imap_tools.MailAttachment) -> str:
    with open(f"attachments/custom_filename", "wb") as f:
        f.write(attachment.payload)
    return "attachments/custom_filename"

This loader is designed to be used as a way to load data into LlamaIndex.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama_index_readers_imap-0.2.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llama_index_readers_imap-0.2.1-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file llama_index_readers_imap-0.2.1.tar.gz.

File metadata

File hashes

Hashes for llama_index_readers_imap-0.2.1.tar.gz
Algorithm Hash digest
SHA256 cb09f41e36ccd8de5c4829fca5bc128ee9c51ada7b389fce45d685706ded7c24
MD5 f30e355271d86f2bc0dcbaf9fb7b6e7f
BLAKE2b-256 0ec37c93fc84d3c62c5f6c130cf92232b7bee3eb3ecb76ad52702c710f655621

See more details on using hashes here.

File details

Details for the file llama_index_readers_imap-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llama_index_readers_imap-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 be55c188bb5c5fca7745307ef08ae5b23442c93cc646fca7a9ab0de507d0d56e
MD5 2e96f7b9903a9932ad09a91a44838377
BLAKE2b-256 9cc0d7d6f259f2a40f5bb4c51aa99c16e0a7267d9283e7402c67f61cb94c8373

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page