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

bool Status::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 45 of file status.cpp.

References Akonadi::HandlerHelper::collectionFromIdOrName(), Akonadi::Handler::failureResponse(), Akonadi::HandlerHelper::itemCount(), Akonadi::HandlerHelper::itemWithFlagCount(), Akonadi::HandlerHelper::itemWithoutFlagCount(), Akonadi::ImapParser::parseParenthesizedList(), Akonadi::ImapParser::parseString(), Akonadi::HandlerHelper::pathForCollection(), Akonadi::Handler::responseAvailable(), Akonadi::Response::setString(), Akonadi::Response::setSuccess(), Akonadi::Response::setTag(), Akonadi::Response::setUntagged(), Akonadi::AkonadiConnection::storageBackend(), Akonadi::Handler::tag(), and Akonadi::DataStore::uidNext().

{
    // Arguments: mailbox name
    //            status data item names

    // Syntax:
    // status     = "STATUS" SP mailbox SP "(" status-att *(SP status-att) ")"
    // status-att = "MESSAGES" / "RECENT" / "UIDNEXT" / "UIDVALIDITY" / "UNSEEN"
    const int startOfCommand = line.indexOf( ' ' ) + 1;
    const int startOfMailbox = line.indexOf( ' ', startOfCommand ) + 1;
    QByteArray mailbox;
    const int endOfMailbox = ImapParser::parseString( line, mailbox, startOfMailbox );
    QList<QByteArray> attributeList;
    ImapParser::parseParenthesizedList( line, attributeList, endOfMailbox );

    Response response;

    DataStore *db = connection()->storageBackend();
    Location l = HandlerHelper::collectionFromIdOrName( mailbox );

    if ( !l.isValid() )
        return failureResponse( "No status for this folder" );

    // Responses:
    // REQUIRED untagged responses: STATUS

    // build STATUS response
    QByteArray statusResponse;
    // MESSAGES - The number of messages in the mailbox
    if ( attributeList.contains( "MESSAGES" ) ) {
        statusResponse += "MESSAGES ";
        const int count = HandlerHelper::itemCount( l );
        if ( count < 0 )
          return failureResponse( "Could not determine message count." );
        statusResponse += QByteArray::number( count );
    }
    // RECENT - The number of messages with the \Recent flag set
    if ( attributeList.contains( "RECENT" ) ) {
        if ( !statusResponse.isEmpty() )
            statusResponse += " RECENT ";
        else
            statusResponse += "RECENT ";
        const int count = HandlerHelper::itemWithFlagCount( l, QLatin1String( "\\Recent" ) );
        if ( count < 0 )
          return failureResponse( "Could not determine recent item count" );
        statusResponse += QByteArray::number( count );
    }
    // UIDNEXT - The next unique identifier value of the mailbox
    if ( attributeList.contains( "UIDNEXT" ) ) {
        if ( !statusResponse.isEmpty() )
            statusResponse += " UIDNEXT ";
        else
            statusResponse += "UIDNEXT ";
        statusResponse += QByteArray::number( db->uidNext() );
    }
    // UIDVALIDITY - The unique identifier validity value of the mailbox
    if ( attributeList.contains( "UIDVALIDITY" ) ) {
        if ( !statusResponse.isEmpty() )
            statusResponse += " UIDVALIDITY 1";
        else
            statusResponse += "UIDVALIDITY 1";
    }
    if ( attributeList.contains( "UNSEEN" ) ) {
        if ( !statusResponse.isEmpty() )
            statusResponse += " UNSEEN ";
        else
            statusResponse += "UNSEEN ";

        const int count = HandlerHelper::itemWithoutFlagCount( l, QLatin1String( "\\Seen" ) );
        if ( count < 0 )
          return failureResponse( "Unable to retrieve unread count" );
        statusResponse += QByteArray::number( count );
    }

    response.setUntagged();
    response.setString( "STATUS \"" + HandlerHelper::pathForCollection( l ).toUtf8() + "\" (" + statusResponse + ')' );
    emit responseAvailable( response );

    response.setSuccess();
    response.setTag( tag() );
    response.setString( "STATUS completed" );
    emit responseAvailable( response );

    deleteLater();
    return true;
}


Generated by  Doxygen 1.6.0   Back to index