示例#1
0
void CMapiMessage::ProcessHeaders( void)
{
  m_bHasSubject = FALSE;
  m_bHasFrom = FALSE;
  m_bHasDate = FALSE;

  PC_S8 pChar = (PC_S8) m_headers.get();
  int start = 0;
  int len = 0;
  int hdrLen = strlen(pChar);
  nsCString line;
  nsCString mid;
  while (*pChar) {
    if ((*pChar == 0x0D) && (*(pChar + 1) == 0x0A)) {
      if ((*(pChar + 2) != ' ') && (*(pChar + 2) != 9)) {
        m_headers.Mid( mid, start, len);
        line += mid;
        ProcessHeaderLine( line);
        line.Truncate();
        pChar++; // subsequent increment will move pChar to the next line
        start += len;
        start += 2;
        len = -1;
      }
    }
    pChar++;
    len++;
  }

  // See if we still have data to be processed.
  if (start < hdrLen)
  {
    line.Assign(m_headers.get()+start);
    ProcessHeaderLine(line);
  }

  if (!m_mimeContentType.IsEmpty() || !m_mimeBoundary.IsEmpty() || !m_mimeCharset.IsEmpty()) {
    MAPI_TRACE1("\tDecoded mime content type: %s\r\n", m_mimeContentType.get());
    MAPI_TRACE1("\tDecoded mime boundary: %s\r\n", m_mimeBoundary.get());
    MAPI_TRACE1("\tDecoded mime charset: %s\r\n", m_mimeCharset.get());
  }
}
示例#2
0
int Response::pump( const unsigned char* data, int datasize )
{
	assert( datasize != 0 );
	int count = datasize;

	while( count > 0 && m_State != COMPLETE )
	{
		if( m_State == STATUSLINE ||
			m_State == HEADERS ||
			m_State == TRAILERS ||
			m_State == CHUNKLEN ||
			m_State == CHUNKEND )
		{
			// we want to accumulate a line
			while( count > 0 )
			{
				char c = (char)*data++;
				--count;
				if( c == '\n' )
				{
					// now got a whole line!
					switch( m_State )
					{
						case STATUSLINE:
							ProcessStatusLine( m_LineBuf );
							break;
						case HEADERS:
							ProcessHeaderLine( m_LineBuf );
							break;
						case TRAILERS:
							ProcessTrailerLine( m_LineBuf );
							break;
						case CHUNKLEN:
							ProcessChunkLenLine( m_LineBuf );
							break;
						case CHUNKEND:
							// just soak up the crlf after body and go to next state
							assert( m_Chunked == true );
							m_State = CHUNKLEN;
							break;
						default:
							break;
					}
					m_LineBuf.clear();
					break;		// break out of line accumulation!
				}
				else
				{
					if( c != '\r' )		// just ignore CR
						m_LineBuf += c;
				}
			}
		}
		else if( m_State == BODY )
		{
			int bytesused = 0;
			if( m_Chunked )
				bytesused = ProcessDataChunked( data, count );
			else
				bytesused = ProcessDataNonChunked( data, count );
			data += bytesused;
			count -= bytesused;
		}
	}

	// return number of bytes used
	return datasize - count;
}