Logo Search packages:      
Sourcecode: akonadi version File versions  Download package

bool Akonadi::AkAppend::handleLine ( const QByteArray &  line  )  [virtual]

Process one line of input.

Parameters:
line The input.
Returns:
false if the handler expects to read more data from the client, true otherwise.

Reimplemented from Akonadi::Handler.

Definition at line 46 of file akappend.cpp.

References Akonadi::ImapParser::parseDateTime(), Akonadi::ImapParser::parseNumber(), Akonadi::ImapParser::parseParenthesizedList(), Akonadi::ImapParser::parseQuotedString(), Akonadi::ImapParser::parseString(), and Akonadi::ImapParser::splitVersionedKey().

{
    // Arguments:  mailbox name
    //        OPTIONAL flag parenthesized list
    //        OPTIONAL date/time string
    //        (partname literal)+
    //
    // Syntax:
    // x-akappend = "X-AKAPPEND" SP mailbox [SP flag-list] [SP date-time] SP (partname SP literal)+

    const int startOfCommand = line.indexOf( ' ' ) + 1;
    const int startOfMailbox = line.indexOf( ' ', startOfCommand ) + 1;
    const int startOfFlags = ImapParser::parseString( line, m_mailbox, startOfMailbox ) + 1;

    // parse optional flag parenthesized list
    // Syntax:
    // flag-list      = "(" [flag *(SP flag)] ")"
    // flag           = "\Answered" / "\Flagged" / "\Deleted" / "\Seen" /
    //                  "\Draft" / flag-keyword / flag-extension
    //                    ; Does not include "\Recent"
    // flag-extension = "\" atom
    // flag-keyword   = atom
    int startOfDateTime = startOfFlags;
    if ( line[startOfFlags] == '(' ) {
        startOfDateTime = ImapParser::parseParenthesizedList( line, m_flags, startOfFlags ) + 1;
    }
    m_flags.append( "\\Recent" ); // the Recent flag always has to be set

    // parse optional date/time string
    int startOfPartSpec = startOfDateTime;
    if ( line[startOfDateTime] == '"' ) {
      startOfPartSpec = ImapParser::parseDateTime( line, m_dateTime, startOfDateTime );
      // FIXME Should we return an error if m_dateTime is invalid?
    }
    // if date/time is not given then it will be set to the current date/time
    // by the database

    // parse part specification
    QList<QPair<QByteArray, QPair<qint64, int> > > partSpecs;
    QByteArray partName;
    qint64 partSize;
    bool ok;

    int pos = startOfPartSpec + 1; // skip opening '('
    int endOfPartSpec = line.indexOf( ')', startOfPartSpec );
    while( pos < endOfPartSpec ) {
      if( line[pos] == ',' )
        pos++; // skip ','

      pos = ImapParser::parseQuotedString( line, partName, pos );
      pos++; // skip ':'
      pos = ImapParser::parseNumber( line, partSize, &ok, pos );
      if( !ok )
        partSize = 0;

      int version = 0;
      QByteArray plainPartName;
      ImapParser::splitVersionedKey( partName, plainPartName, version );

      partSpecs.append( qMakePair( plainPartName, qMakePair( partSize, version ) ) );
    }

    QByteArray allParts;
    ImapParser::parseString( line, allParts, endOfPartSpec + 1 );

    // chop up literal data in parts
    pos = 0; // traverse through part data now
    QPair<QByteArray, QPair<qint64, int> > partSpec;
    foreach( partSpec, partSpecs ) {
      // wrap data into a part
      Part part;
      part.setName( QLatin1String( partSpec.first ) );
      part.setData( allParts.mid( pos, partSpec.second.first ) );
      if ( partSpec.second.second != 0 )
        part.setVersion( partSpec.second.second );
      m_parts.append( part );
      pos += partSpec.second.first;
    }

    return commit();
}


Generated by  Doxygen 1.6.0   Back to index