Skip to main content

Overview

A thread (or conversation) is a group of related messages linked together by their reply chain. When you reply to an email, Jasni automatically maintains proper threading so messages appear grouped in the recipient’s email client.

How Threading Works

Email threading relies on three headers:
HeaderDescription
Message-IDUnique identifier for each email
In-Reply-ToReferences the parent email’s Message-ID
ReferencesFull chain of Message-IDs in the thread
When you use Jasni’s reply or forward endpoints, these headers are automatically set correctly.

Replying to Messages

Reply to a message with proper threading:
POST /api/v1/emails/123/[email protected]
{
  "text": "Thanks for your message!",
  "replyAll": false,
  "includeOriginal": true
}
Jasni automatically:
  • Sets the correct In-Reply-To and References headers
  • Determines the correct recipients
  • Adds Re: prefix to the subject
  • Quotes the original message (if includeOriginal is true)

Reply vs Reply All

OptionBehavior
replyAll: falseReply only to the sender
replyAll: trueReply to sender and all CC recipients

Forwarding Messages

Forward a message to new recipients:
POST /api/v1/emails/123/[email protected]
{
  "to": ["[email protected]"],
  "text": "FYI - see below"
}
Forwarded emails:
  • Maintain the original thread context
  • Add Fwd: prefix to the subject
  • Include the original message content

Thread Structure Example

Thread: "Project Update"
├── Message 1: "Project Update" (from: alice@...)
│   └── Message 2: "Re: Project Update" (from: bob@...)
│       └── Message 3: "Re: Project Update" (from: alice@...)
│           └── Message 4: "Re: Project Update" (from: charlie@...)
Each reply links back to its parent via In-Reply-To, and contains the full chain in References.

Building Thread Views

To display a conversation view in your application:
  1. Fetch messages from a folder
  2. Group messages by their References or root Message-ID
  3. Sort within each group by date
// Example: Group messages into threads
function groupIntoThreads(messages) {
  const threads = new Map();
  
  for (const message of messages) {
    // Get the root message ID from References or use Message-ID
    const threadId = message.references?.[0] || message.messageId;
    
    if (!threads.has(threadId)) {
      threads.set(threadId, []);
    }
    threads.get(threadId).push(message);
  }
  
  // Sort messages within each thread by date
  for (const thread of threads.values()) {
    thread.sort((a, b) => new Date(a.date) - new Date(b.date));
  }
  
  return threads;
}

Best Practices

Don’t manually construct reply headers. Use the /reply endpoint to ensure proper threading.
Avoid changing the subject line in replies, as some email clients use the subject for threading.
When replying, set includeOriginal: true to quote the original message for context.