From f242e6338a332e2f84b03a437c79cfbf4da7d217 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Wed, 10 Jul 2013 21:07:43 -0400 Subject: [PATCH] StrBufStripAllBut() now returns the LEFTMOST qualifying substring. This allows mail to be received from brain-damaged Microsoft MTAs that place additional superfluous angle-bracketed strings on the MAIL FROM line. Bill Gates is Hitler. --- libcitadel/lib/stringbuf.c | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index 103377bba..bd67e0d48 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1987-2011 by the citadel.org team + * Copyright (c) 1987-2013 by the citadel.org team * * This program is open source software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -1173,29 +1173,31 @@ void StrBufSpaceToBlank(StrBuf *Buf) void StrBufStripAllBut(StrBuf *Buf, char leftboundary, char rightboundary) { - const char *pBuff; const char *pLeft; const char *pRight; - if ((Buf == NULL) || (Buf->buf == NULL)) + if ((Buf == NULL) || (Buf->buf == NULL)) { + StrBufCutAt(Buf, 0, Buf->buf); return; - pLeft = pBuff = Buf->buf; - while (pBuff != NULL) { - pLeft = pBuff; - pBuff = strchr(pBuff, leftboundary); - if (pBuff != NULL) - pBuff++; } - - if (pLeft != NULL) - pBuff = pLeft; - else - pBuff = Buf->buf; - pRight = strchr(pBuff, rightboundary); - if (pRight != NULL) + + pRight = strchr(Buf->buf, rightboundary); + if (pRight != NULL) { StrBufCutAt(Buf, 0, pRight); - if (pLeft != NULL) - StrBufCutLeft(Buf, pLeft - Buf->buf); + } + else { + StrBufCutAt(Buf, 0, Buf->buf); + return; + } + + pLeft = strrchr(ChrPtr(Buf), leftboundary); + if (pLeft != NULL) { + StrBufCutLeft(Buf, pLeft - Buf->buf + 1); + } + else { + StrBufCutAt(Buf, 0, Buf->buf); + return; + } } -- 2.30.2