From 49774900fb8798096e009cf9948e03c5472cfcbf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Sat, 8 Oct 2011 19:25:10 +0000 Subject: [PATCH] * Now sanitizes the white space in the header fields before adding them to the message (ie. multiple spaces are compressed to a single one, tabs and other white space is replaced with a space). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42810 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/kits/mail/HaikuMailFormatFilter.cpp | 32 ++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/kits/mail/HaikuMailFormatFilter.cpp b/src/kits/mail/HaikuMailFormatFilter.cpp index 7b711effe4..b65f861c22 100644 --- a/src/kits/mail/HaikuMailFormatFilter.cpp +++ b/src/kits/mail/HaikuMailFormatFilter.cpp @@ -8,8 +8,9 @@ #include "HaikuMailFormatFilter.h" -#include +#include +#include #include #include @@ -47,6 +48,34 @@ static const mail_header_field gDefaultFields[] = { }; +//! Replaces tabs and other white space with spaces, compresses spaces. +void +sanitize_white_space(BString& string) +{ + char* buffer = string.LockBuffer(string.Length() + 1); + if (buffer == NULL) + return; + + int32 count = string.Length(); + int32 spaces = 0; + for (int32 i = 0; buffer[i] != '\0'; i++, count--) { + if (isspace(buffer[i])) { + buffer[i] = ' '; + spaces++; + } else { + if (spaces > 1) + memmove(buffer + i + 1 - spaces, buffer + i, count + 1); + spaces = 0; + } + } + + string.UnlockBuffer(); +} + + +// #pragma mark - + + HaikuMailFormatFilter::HaikuMailFormatFilter(MailProtocol& protocol, BMailAccountSettings* settings) : @@ -86,6 +115,7 @@ HaikuMailFormatFilter::HeaderFetched(const entry_ref& ref, BFile* file) switch (gDefaultFields[i].attr_type){ case B_STRING_TYPE: + sanitize_white_space(target); attributes.AddString(gDefaultFields[i].attr_name, target); break;