-
-
Notifications
You must be signed in to change notification settings - Fork 166
Description
Issue Update: MML <#part> creates inline text, not MIME attachments; has_attachment always false
Summary
Two distinct bugs confirmed:
- MML
<#part>directive fails to create MIME attachments — file content is inlined as plain text has_attachmentJSON field always returnsfalseregardless 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>
EOFActual 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 jsonActual 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
-
MML tokenizer finds no parts: The trace
no content type found, guessing from body: text/plainsuggests the MML compiler treats the entire template as a single plain text body. -
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. -
has_attachmentdetection is completely broken: Even when attachments are created by external tools, the JSON flag is alwaysfalse. -
Disparity between IMAP providers: I saw another issue mentioning Fastmail works correctly. This may be Gmail-specific.
Questions for Maintainers
- Is this a known issue with Gmail IMAP specifically?
- Does MML require
Content-Type: multipart/mixedheader explicitly declared? - Is
has_attachmentbased on MIME structure detection or IMAP flags?
Happy to provide more debug output, packet captures, or test specific builds.