------- You are receiving this mail because: -------
You are the QA contact for the bug, or are watching the QA contact.
http://www.exim.org/bugzilla/show_bug.cgi?id=455
holmgren@??? changed:
What |Removed |Added
----------------------------------------------------------------------------
AssignedTo|ph10@??? |holmgren@???
Status|NEW |ASSIGNED
------- Comment #2 from holmgren@??? 2007-01-27 17:50 -------
Created an attachment (id=54)
--> (
http://www.exim.org/bugzilla/attachment.cgi?id=54&action=view)
Let smtp_respond() perform the wrapping
I post the full function here as well. It features some improvements over the
old code:
- Can break lines at separators, not just spaces (not necessarily a good idea
since we should probably avoid wrapping email addresses).
- Enforces the maximum response line length (512 bytes).
- Trims off whitespace that ends up at the end or beginning of a line (the
later not necessarily a wanted behaviour).
- Sends one long line if no_multiline_responses is set. Can the software that
can't handle multiline responses handle long lines?
I had an idea that we should only break after a colon if everything thereafter
up to the next newline or the end of the string can fit on the next line, but
that's probably not worth it.
void
smtp_respond(uschar* code, int codelen, BOOL final, uschar *msg)
{
int esclen = 0;
uschar *esc = US"";
if (!final && no_multiline_responses) return;
if (codelen > 4)
{
esc = code + 4;
esclen = codelen - 4;
}
while (isspace(*msg)) msg++;
for (;;)
{
int i;
uschar *eol = NULL, *colon = NULL, *p = msg;
/* Break a long message into a multiline message. This works as follows:
If a newline or terminating null is found, stop.
If the line so far is at least 35 characters and a suitable break point
is found, remember it. Colons are remembered specially.
If the line so far is at least 75 characters and a suitable break point
has been found, stop.
If the maximum line length is reached, stop even if no break point has
been found.
If no_multiline_responses is true, we don't look for places to break,
only newlines. Lines can be long instead.
*/
for (i = 0; (!eol || i < 75) && i < 509 - codelen; i++)
{
if (*p == '\0' || *p == '\n')
{
eol = p;
break;
}
else if (i > 35 && !no_multiline_responses)
{
if (strchr(",;:!?)]}>/&+-=*^|", *(p-1))
|| strchr("([{<#$\\", *p))
{
eol = p;
if (*(p-1) == ':') colon = eol;
}
else if (isspace(*p)) eol = p;
}
p++;
}
/* We prefer breaking after a colon if there is one */
if (colon) eol = colon;
if (!eol) eol = p; /* Last resort */
else p = eol;
if (*msg)
while (isspace(*(eol-1))) eol--; /* Trim end of line */
while (isspace(*p)) p++; /* See if there is anything but space left */
if (*p == '\0' || no_multiline_responses) /* Apparently we found the last
line */
{
smtp_printf("%.3s%c%.*s%.*s\r\n", code, final? ' ':'-', esclen, esc,
(int)(eol - msg), msg);
return;
}
else
{
smtp_printf("%.3s-%.*s%.*s\r\n", code, esclen, esc, (int)(eol - msg), msg);
msg = p;
}
}
}
--
Configure bugmail:
http://www.exim.org/bugzilla/userprefs.cgi?tab=email