git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH 8/8] wrap_in_html(): process message in bulk rather than line-by-line

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Nov 30, 2012, 13:40 UTC
Message-ID
<50B8B73A.4060801@alum.mit.edu>
In-Reply-To
<7v7gp4p00u.fsf@alter.siamese.dyndns.org>
On 11/29/2012 10:33 PM, Junio C Hamano wrote:
Show 14 quoted lines
> Michael Haggerty <mhagger@alum.mit.edu> writes:
> 
>> Now that we can xml-quote an arbitrary string in O(N), there is no
>> reason to process the message line by line.  This change saves lots of
>> memory allocations and copying.
>>
>> The old code would have created invalid output for a malformed input
>> message (one that does not contain a blank line separating the header
>> from the body).  The new code die()s in this situation.
> 
> Given that imap-send is about sending a patch the distinction would
> not matter in practice, but isn't the difference between the two
> that the new version would not allow sending a header-only message
> without a body, while the old one allowed it?

I was thinking that the end-of-header line is a required part of an RFC2282 email message, but I was wrong. If you squash the attached patch onto this commit, it will handle emails without bodies correctly.

Nevertheless, the old code was even *more* broken because it added a "</pre>" regardless of whether the separator line had been seen, and therefore a message without an end-of-header line would come out like

    Header1: foo
    Header2: bar
    </pre>

with no content_type line, no pre_open, and </pre> appended to the header without a blank line in between. This is the "invalid output" that I was referring to.

Michael
-- 
Michael Haggerty
mhagger@alum.mit.edu
http://softwareswirl.blogspot.com/


diff --git a/imap-send.c b/imap-send.c
index eec9e35..e521e2f 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1348,7 +1348,7 @@ static void wrap_in_html(struct strbuf *msg)
 	const char *body = strstr(msg->buf, "\n\n");
 
 	if (!body)
-		die("malformed message");
+		return; /* Headers but no body; no wrapping needed */
 
 	body += 2;
 
Previous: Junio C HamanoNext: Junio C Hamano
Message 16 of 18 in “Add function strbuf_addstr_xml_quoted() and more”
  1. 0/8 Add function strbuf_addstr_xml_quoted() and moreMichael Haggerty, Nov 25, 2012
  2. 1/8 Add new function strbuf_add_xml_quoted()Michael Haggerty, Nov 25, 2012
  3. 2/8 xml_entities(): use function strbuf_addstr_xml_quoted()Michael Haggerty, Nov 25, 2012
  4. 3/8 lf_to_crlf(): NUL-terminate msg_data::dataMichael Haggerty, Nov 25, 2012
  5. 4/8 imap-send: store all_msgs as a strbufMichael Haggerty, Nov 25, 2012
  6. 5/8 imap-send: correctly report errors reading from stdinMichael Haggerty, Nov 25, 2012
  7. 6/8 imap-send: change msg_data from storing (char *, len) to storing strbufMichael Haggerty, Nov 25, 2012
  8. Junio C HamanoNov 29, 2012
  9. Jeff KingNov 29, 2012
  10. Michael HaggertyNov 30, 2012
  11. Junio C HamanoDec 2, 2012
  12. Michael HaggertyDec 2, 2012
  13. Thiago FarinaDec 3, 2012
  14. 7/8 wrap_in_html(): use strbuf_addstr_xml_quoted()Michael Haggerty, Nov 25, 2012
  15. Junio C HamanoNov 29, 2012
  16. Michael HaggertyNov 30, 2012
  17. Junio C HamanoDec 2, 2012
  18. Michael HaggertyDec 2, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.