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

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for llama_index_readers_imap-0.2.2.tar.gz
Algorithm Hash digest
SHA256 4fd89f22436f202b0517c7d76ee0cb4834aef851e12d53d370032191386ddfd2
MD5 41012dbde1ed0402553c2a3516f1ad4d
BLAKE2b-256 fe2367febe7caaa98ce01f06dc0c6366a8efe6e8f5f3c60987020d9c50a9c65e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for llama_index_readers_imap-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 168daa2dddc12d542a4fd621faddc502044f8194befd25c423379d910dc31c17
MD5 69578697a78987439e57b3c14192b16c
BLAKE2b-256 2fb55b30d04ab97cfd46ea57f08e669a1573ee08e7e9bc504c9d5c1caa0a3d23

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