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.0.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.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for llama_index_readers_imap-0.2.0.tar.gz
Algorithm Hash digest
SHA256 f43af25f967845aee94242b276f7ca5a18fd6f530be0981508ca0ec2cc8d99e1
MD5 4b459c8d20b146b76eaa178daf78a987
BLAKE2b-256 8549f51cc14f552c7812e542d82aff800d47a1c1ade05b3641a500b7753f429d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_readers_imap-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 eb4e5f3a123795bc7037afd16a5547dd4ac3f2a7c08abc1307621c7b4e6501f3
MD5 34dcd2b944f27a3fb3a2f22a91e39f82
BLAKE2b-256 af4d9ba6c2bd72e34bbbbe906cb8197f37788a83fbfd4ea2ffbbe081a95f0f97

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