From 1978c49bea5b439d993067c055cec47e70db8fd6 Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Sat, 7 Oct 2023 22:33:50 +0200 Subject: minor refactoring --- src/mime-parsefull.cc | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) (limited to 'src/mime-parsefull.cc') diff --git a/src/mime-parsefull.cc b/src/mime-parsefull.cc index 50d3157..5d5d836 100644 --- a/src/mime-parsefull.cc +++ b/src/mime-parsefull.cc @@ -1,9 +1,10 @@ -/** -------------------------------------------------------------------- +/** * @file mime-parsefull.cc * @brief Implementation of main mime parser components * @author Andreas Aardal Hanssen * @date 2002-2005 - * ----------------------------------------------------------------- **/ + */ + #include "convert.h" #include "mime-inputsource.h" #include "mime-utils.h" @@ -20,11 +21,11 @@ #include #include -Binc::MimeInputSource *mimeSource = 0; +Binc::MimeInputSource *mimeSource = nullptr; -using namespace ::std; +using std::string; +using std::vector; -//------------------------------------------------------------------------ void Binc::MimeDocument::parseFull(int fd) const { if (allIsParsed) return; @@ -58,7 +59,6 @@ void Binc::MimeDocument::parseFull(int fd) const size = mimeSource->getOffset(); } -//------------------------------------------------------------------------ static bool parseOneHeaderLine(Binc::Header *header, unsigned int *nlines) { using namespace ::Binc; @@ -139,14 +139,12 @@ static bool parseOneHeaderLine(Binc::Header *header, unsigned int *nlines) return !(eof || endOfHeaders); } -//------------------------------------------------------------------------ static void parseHeader(Binc::Header *header, unsigned int *nlines) { while (parseOneHeaderLine(header, nlines)) { } } -//------------------------------------------------------------------------ static void analyzeHeader(Binc::Header *header, bool *multipart, bool *messagerfc822, @@ -211,7 +209,7 @@ static void parseMessageRFC822(vector *members, unsigned int *nbodylines, const string &toboundary) { - using namespace ::Binc; + using namespace Binc; // message rfc822 means a completely enclosed mime document. we // call the parser recursively, and pass on the boundary string @@ -230,11 +228,10 @@ static void parseMessageRFC822(vector *members, *bodylength = mimeSource->getOffset(); if (*bodylength >= bodystartoffsetcrlf) { *bodylength -= bodystartoffsetcrlf; - if (*bodylength >= (unsigned int)bsize) { + if (*bodylength >= (unsigned int)bsize) *bodylength -= (unsigned int)bsize; - } else { + else *bodylength = 0; - } } else { *bodylength = 0; } @@ -247,7 +244,7 @@ static void parseMessageRFC822(vector *members, static bool skipUntilBoundary(const string &delimiter, unsigned int *nlines, bool *eof) { int endpos = delimiter.length(); - char *delimiterqueue = 0; + char *delimiterqueue = nullptr; int delimiterpos = 0; const char *delimiterStr = delimiter.c_str(); if (delimiter != "") { @@ -282,7 +279,7 @@ static bool skipUntilBoundary(const string &delimiter, unsigned int *nlines, boo } delete[] delimiterqueue; - delimiterqueue = 0; + delimiterqueue = nullptr; return foundBoundary; } @@ -338,9 +335,9 @@ static void parseMultipart(const string &boundary, // This exception is to handle a special case where the // delimiter of one part is not followed by CRLF, but // immediately followed by a CRLF prefixed delimiter. - if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b)) + if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b)) { *eof = true; - else if (a == '-' && b == '-') { + } else if (a == '-' && b == '-') { mimeSource->ungetChar(); mimeSource->ungetChar(); mimeSource->ungetChar(); @@ -415,9 +412,9 @@ static void parseMultipart(const string &boundary, // This exception is to handle a special case where the // delimiter of one part is not followed by CRLF, but // immediately followed by a CRLF prefixed delimiter. - if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b)) + if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b)) { *eof = true; - else if (a == '-' && b == '-') { + } else if (a == '-' && b == '-') { mimeSource->ungetChar(); mimeSource->ungetChar(); mimeSource->ungetChar(); @@ -439,11 +436,10 @@ static void parseMultipart(const string &boundary, *bodylength = mimeSource->getOffset(); if (*bodylength >= bodystartoffsetcrlf) { *bodylength -= bodystartoffsetcrlf; - if (*bodylength >= (unsigned int)*boundarysize) { + if (*bodylength >= (unsigned int)*boundarysize) *bodylength -= (unsigned int)*boundarysize; - } else { + else *bodylength = 0; - } } else { *bodylength = 0; } @@ -471,7 +467,7 @@ static void parseSinglePart(const string &toboundary, // if (skipUntilBoundary(_toboundary, nlines, eof)) // *boundarysize = _toboundary.length(); - char *boundaryqueue = 0; + char *boundaryqueue = nullptr; int endpos = _toboundary.length(); if (toboundary != "") { boundaryqueue = new char[endpos]; @@ -525,9 +521,9 @@ static void parseSinglePart(const string &toboundary, // This exception is to handle a special case where the // delimiter of one part is not followed by CRLF, but // immediately followed by a CRLF prefixed delimiter. - if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b)) + if (!mimeSource->getChar(&a) || !mimeSource->getChar(&b)) { *eof = true; - else if (a == '-' && b == '-') { + } else if (a == '-' && b == '-') { mimeSource->ungetChar(); mimeSource->ungetChar(); mimeSource->ungetChar(); @@ -548,17 +544,15 @@ static void parseSinglePart(const string &toboundary, *bodylength = mimeSource->getOffset(); if (*bodylength >= bodystartoffsetcrlf) { *bodylength -= bodystartoffsetcrlf; - if (*bodylength >= (unsigned int)*boundarysize) { + if (*bodylength >= (unsigned int)*boundarysize) *bodylength -= (unsigned int)*boundarysize; - } else { + else *bodylength = 0; - } } else { *bodylength = 0; } } -//------------------------------------------------------------------------ int Binc::MimePart::parseFull(const string &toboundary, int &boundarysize) const { headerstartoffsetcrlf = mimeSource->getOffset(); -- cgit v1.2.3