Postfix 2.9.0-RC2, trying to send to an external address with an
apostrophe:
rob0@chestnut:~$ fortune -o | mail -so "Joe's"@example.net
rob0@chestnut:~$ mailq
----Queue ID----- --Size-- ---Arrival Time----
--Sender/Recipient------
3TZMM8068wzp1Qr 405 Fri Jan 27 08:05:08 rob0
Joe'[email protected]
and this is logged:
Jan 27 08:05:08 chestnut postfix/pickup[20923]: 3TZMM80HjFzBn8B2:
uid=1007 from=<rob0>
Jan 27 08:05:08 chestnut postfix/cleanup[20967]: fatal:
dict_sqlite_lookup: /etc/postfix/query/maps-valias.query: SQL prepare
failed: near "s": syntax error?
Jan 27 08:05:09 chestnut postfix/pickup[20923]: warning:
maildrop/3TZMM8068wzp1Qr: error writing 3TZMM80HjFzBn8B2: queue file
write error
Jan 27 08:05:09 chestnut postfix/master[20922]: warning: process
/usr/libexec/postfix/cleanup pid 20967 exit status 1
Jan 27 08:05:09 chestnut postfix/master[20922]: warning:
/usr/libexec/postfix/cleanup: bad command startup -- throttling
Is this just a mailx problem, or is it Postfix failing to escape the
apostrophe?
root@chestnut:~# postcat -q 3TZMM8068wzp1Qr
*** ENVELOPE RECORDS maildrop/3TZMM8068wzp1Qr ***
message_arrival_time: Fri Jan 27 08:05:08 2012
named_attribute: rewrite_context=local
sender_fullname: Rob McGee
sender: rob0
recipient: Joe'[email protected]
*** MESSAGE CONTENTS maildrop/3TZMM8068wzp1Qr ***
Date: Fri, 27 Jan 2012 08:05:08 -0600
To: Joe'[email protected]
Subject: o
User-Agent: Heirloom mailx 12.4 7/29/08
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
"God is as real as I am," the old man said. My faith was restored,
for I knew that Santa would never lie.
*** HEADER EXTRACTED maildrop/3TZMM8068wzp1Qr ***
*** MESSAGE FILE END maildrop/3TZMM8068wzp1Qr ***
root@chestnut:~# postsuper -d 3TZMM8068wzp1Qr
postsuper: 3TZMM8068wzp1Qr: removed
postsuper: Deleted: 1 message
After deleting this from the queue, pickup and cleanup continued on
normally. So to rule out mailx as culprit, I tried SMTP:
rob0@chestnut:~$ telnet localhost 587
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 chestnut.example.net ESMTP Postfix
ehlo localhost
250-chestnut.example.net
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-AUTH PLAIN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:<[email protected]>
250 2.1.0 Ok
rcpt to:<"joe's"@example.net>
and hangs, while this is logged:
Jan 27 08:20:12 chestnut postfix/trivial-rewrite[21028]: fatal:
dict_sqlite_lookup: /etc/postfix/query/maps-transport.query: SQL
prepare failed: near "s": syntax error?
Jan 27 08:20:13 chestnut postfix/master[20922]: warning: process
/usr/libexec/postfix/trivial-rewrite pid 21028 exit status 1
Jan 27 08:20:14 chestnut postfix/trivial-rewrite[21031]: fatal:
dict_sqlite_lookup: /etc/postfix/query/maps-transport.query: SQL
prepare failed: near "s": syntax error?
Jan 27 08:20:15 chestnut postfix/submission/smtpd[21025]: warning:
problem talking to service rewrite: Success
Jan 27 08:20:15 chestnut postfix/master[20922]: warning: process
/usr/libexec/postfix/trivial-rewrite pid 21031 exit status 1
Jan 27 08:20:15 chestnut postfix/master[20922]: warning:
/usr/libexec/postfix/trivial-rewrite: bad command startup --
throttling
Even after disconnecting (telnet escape sequence, it was hung) the
errors in logs continued.
Granted, I am not well-enough versed in SMTP/RFC 5321 to be able to
write a MUA, so perhaps my rcpt to: command was wrong. But the sad
fact remains that many people who have published and distributed
mailer software probably know less than I do. :(
It's bothersome that Garbage In can apparently cause such confusion
within Postfix. Trying again just now, it hangs at the "mail from:"
stage. This Garbage In has caused a DoS. A stop/start was needed to
clear it.
No, I do not "need" transport_maps set; this is a sandbox machine in
testing right now. There are bugs in that query, but it isn't having
serious problems, just not always returning the desired data, until
the apostrophe catastrophe.
The virtual_alias_maps query with which mailx ran into trouble is
verified to work with postmap and in practice. For the record, here
it is:
$ cat /etc/postfix/query/maps-valias.query
dbpath = /etc/postfix/private/mail.sqlite
# Shorthand in this query:
# AA = Alias Address (the address we are looking up)
# AD = Alias Domain (the domain part of that address)
# TA = Target Address (the address we are redirecting to)
# TD = Target Domain (the domain part of that address)
# VA = Virtual Alias
query = SELECT TA.localpart || (CASE WHEN VA.extension IS NOT NULL
THEN '-' || VA.extension ELSE '' END) ||
(CASE WHEN TD.id=0 THEN '' ELSE '@' || TD.name END)
FROM Alias AS VA
JOIN Address AS TA ON (VA.target = TA.id)
JOIN Domain AS TD ON (TA.domain = TD.id)
JOIN Address AS AA ON (VA.address = AA.id)
JOIN Domain AS AD ON (AA.domain = AD.id)
WHERE AA.localpart || '@' || AD.name IS '%s'
AND VA.active!=0
# end
Rather than go into the details of the schema here, suffice to say
that this part is working. The only options sqlite_table(5) gives us
are to use %s or %u and %d. I tried them with and without 'quoting';
the man page examples show the quoting.
All I found in the list archives was a thread from 5 years ago from
someone wanting to block apostrophed localparts, and Victor pointing
out their legitimate use. But how can they be escaped for SQL
queries? Did I miss something in the man page?
**
And on a slightly related matter, in sqlite_table(5), SQLITE
PARAMETERS, "domain":
"... This can significantly reduce the query load on the
SQLite server."
There being no such thing as a SQLite server, it appears that this
text might have been cloned out of a ??sql_table(5) man page; but
it's not relevant here.
--
http://rob0.nodns4.us/ -- system administration and consulting
Offlist GMX mail is seen only if "/dev/rob0" is in the Subject: