spamass-milt-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: subject is deleted instead of rewritten


From: Ronan Waide
Subject: Re: subject is deleted instead of rewritten
Date: Thu, 9 Jan 2003 23:46:00 +0000

*sigh* sent you the pre-correction code.

Note, this compiles, and I think the logic's okay, but I've not
commited it to anything like a testbed.

cheers,
Waider.

// retrieve the content of a specific field in the header
// and return it.
string
retrieve_field(const string& header, const string& field)
{
  // Find the field
  string::size_type field_start = string::npos;
  string::size_type field_end = string::npos;
  string::size_type idx = 0;

  while( field_start == string::npos ) {
        idx = find_nocase( header, field + string(":"), idx );

        // no match
        if ( idx == string::npos ) {
          debug( 3, "r_f: field not found" );
          return string( "" );
        }

        // The string we've found needs to be either at the start of the
        // headers string, or immediately following a "\n"
        if ( idx != 0 ) {
          if ( header[ idx - 1 ] != '\n' ) {
                idx++; // so we don't get stuck in an infinite loop
                continue; // loop around again
          }
        }
  }

  // A mail field starts just after the header. Ideally, there's a
  // space, but it's possible that there isn't.
  field_start += field.length() + 1;
  if ( field_start < ( header.length() - 1 ) && header[ field_start ] == ' ' ) {
        field_start++;
  }

  // See if there's anything left, to shortcut the rest of the
  // function.
  if ( field_start == header.length() - 1 ) {
        return string( "" );
  }

  // The field continues to the end of line. If the start of the next
  // line is whitespace, then the field continues.
  idx = field_start;
  while( field_end == string::npos ) {
        idx = header.find( "\n", idx );

        // if we don't find a "\n", or it's at the end of the headers then
        // gobble everything to the end of the headers
        if (( idx == string::npos ) || ( idx == header.length() - 1 )) {
          field_end = header.length() - 1;
        } else {
          // check the next character
          if (( idx + 1 ) < header.length() && ( isspace( header[ idx + 1 ] ))) 
{
                idx ++; // whitespace found, so wrap to the next line
          } else {
                field_end = idx;
          }
        }
  }

  // possible cleanups:
  //  trim the trailing \n
  //  remove the whitespace picked up when a header wraps - this is
  //    actually a requirement rather than a possible cleanup.
  return header.substr( field_start, field_end - field_start );
};

-- 
address@hidden / Yes, it /is/ very personal of me.
Some people just don't know which side of the good/evil thing to side
with, despite the obvious "fun now, pay later" advantages of the evil
side for those of us who need instant gratification.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]