Skip to content

has_attachment always false in envelope list JSON output #631

@Alfa-ai-ccvs-tech

Description

@Alfa-ai-ccvs-tech

Issue Update: MML <#part> creates inline text, not MIME attachments; has_attachment always false

Summary

Two distinct bugs confirmed:

  1. MML <#part> directive fails to create MIME attachments — file content is inlined as plain text
  2. has_attachment JSON field always returns false regardless of actual attachments

Environment

  • himalaya: v1.1.0 +imap +maildir +smtp +sendmail +wizard +pgp-commands
  • OS: Linux (Pop!_OS) x86_64
  • IMAP: Gmail (imap.gmail.com:993 TLS)
  • SMTP: Gmail (smtp.gmail.com:587 STARTTLS)
  • Config: Standard account, message.send.save-copy = false

Reproduction 1: MML <#part> creates inline text

Steps

# Create test file
echo "BINARY_ATTACHMENT_CONTENT_12345" > /tmp/test-attach.txt

# Send via MML template
cat << 'EOF' | himalaya template send -a myaccount --trace 2>&1 | grep -E '(mml|content|guessing)'
From: sender@gmail.com
To: recipient@example.com
Subject: MML Attachment Test

Body text.

<#part filename=/tmp/test-attach.txt><#/part>
EOF

Actual Trace Output

mml::message::body::compiler::tokens: no content type found, guessing from body: text/plain

Actual Result (email received)

From: sender@gmail.com
To: recipient@example.com
Subject: MML Attachment Test

Body text.

BINARY_ATTACHMENT_CONTENT_12345

Problem: File content is inlined as plain text. No MIME attachment created. Gmail does NOT show this as an attachment.

Expected Result

Email should be Content-Type: multipart/mixed with the file as a separate Content-Disposition: attachment part.

Variations Tested (all fail)

  • <#part filename=/tmp/test-attach.txt><#/part> — content inlined
  • <#part filename=/tmp/test-attach.txt disposition=attachment><#/part> — content inlined
  • <#part type=application/octet-stream filename=/tmp/test-attach.txt><#/part> — tag appears literally in body, not processed

Reproduction 2: has_attachment always false

Steps

# Check envelope of any email with known attachment
himalaya envelope list -a myaccount -f "[Gmail]/Sent Mail" --page-size 5 -o json

Actual Result

{
  "id": "136",
  "subject": "MML Attachment Test",
  "has_attachment": false
}

Expected Result

{
  "id": "136",
  "subject": "MML Attachment Test",
  "has_attachment": true
}

Note: This applies to ALL folders (INBOX, Sent Mail, etc.) and ALL emails, including those with verified Content-Type: multipart/mixed in raw headers.


Verification: Python SMTP creates real attachments

To confirm this is a himalaya/MML issue, not Gmail/IMAP:

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email import encoders

msg = MIMEMultipart()
msg['From'] = 'sender@gmail.com'
msg['To'] = 'recipient@example.com'
msg['Subject'] = 'Python SMTP Test'

msg.attach(MIMEText('Body text.', 'plain'))

with open('/tmp/test-attach.txt', 'rb') as f:
    part = MIMEBase('application', 'octet-stream')
    part.set_payload(f.read())
    encoders.encode_base64(part)
    part.add_header('Content-Disposition', 'attachment', filename='test-attach.txt')
    msg.attach(part)

with smtplib.SMTP('smtp.gmail.com', 587) as server:
    server.starttls()
    server.login('sender@gmail.com', 'password')
    server.send_message(msg)

Result: Content-Type: multipart/mixed with proper attachment. Gmail displays it correctly. himalaya shows:

Body text.

<#part type=application/octet-stream filename="test-attach.txt"><#/part>

(This is himalaya's MML representation of actual MIME attachment parts.)


Key Observations

  1. MML tokenizer finds no parts: The trace no content type found, guessing from body: text/plain suggests the MML compiler treats the entire template as a single plain text body.

  2. File content is read and inlined: The <#part filename=...> tag IS being processed (file content appears), but as inline text, not as a MIME part.

  3. has_attachment detection is completely broken: Even when attachments are created by external tools, the JSON flag is always false.

  4. Disparity between IMAP providers: I saw another issue mentioning Fastmail works correctly. This may be Gmail-specific.


Questions for Maintainers

  1. Is this a known issue with Gmail IMAP specifically?
  2. Does MML require Content-Type: multipart/mixed header explicitly declared?
  3. Is has_attachment based on MIME structure detection or IMAP flags?

Happy to provide more debug output, packet captures, or test specific builds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions