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

bool Akonadi::Modify::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 40 of file modify.cpp.

References Akonadi::DataStore::addCollectionAttribute(), Akonadi::DataStore::appendMimeTypeForLocation(), Akonadi::NotificationCollector::collectionChanged(), Akonadi::HandlerHelper::collectionFromIdOrName(), Akonadi::Transaction::commit(), Akonadi::Handler::failureResponse(), Akonadi::DataStore::notificationCollector(), Akonadi::HandlerHelper::parseCachePolicy(), Akonadi::ImapParser::parseNumber(), Akonadi::ImapParser::parseParenthesizedList(), Akonadi::ImapParser::parseString(), Akonadi::DataStore::removeCollectionAttribute(), Akonadi::DataStore::removeMimeTypesForLocation(), Akonadi::DataStore::renameLocation(), Akonadi::Handler::responseAvailable(), Akonadi::Response::setString(), Akonadi::Response::setTag(), Akonadi::AkonadiConnection::storageBackend(), and Akonadi::Handler::tag().

{
  int pos = line.indexOf( ' ' ) + 1; // skip tag
  pos = line.indexOf( ' ', pos ); // skip command
  if ( pos < 0 )
    return failureResponse( "Invalid syntax" );

  QByteArray collection;
  pos = ImapParser::parseString( line, collection, pos );
  Location location = HandlerHelper::collectionFromIdOrName( collection );
  if ( !location.isValid() )
    return failureResponse( "No such collection" );
  if ( location.id() == 0 )
    return failureResponse( "Cannot modify root collection" );

  DataStore *db = connection()->storageBackend();
  Transaction transaction( db );

  while ( pos < line.length() ) {
    QByteArray type;
    pos = ImapParser::parseString( line, type, pos );
    if ( type == "MIMETYPE" ) {
      QList<QByteArray> mimeTypes;
      pos = ImapParser::parseParenthesizedList( line, mimeTypes, pos );
      if ( !db->removeMimeTypesForLocation( location.id() ) )
        return failureResponse( "Unable to modify collection mimetypes." );
      QStringList mts;
      foreach ( const QByteArray &ba, mimeTypes )
        mts << QString::fromLatin1(ba);
      if ( !db->appendMimeTypeForLocation( location.id(), mts ) )
        return failureResponse( "Unable to modify collection mimetypes." );
    } else if ( type == "CACHEPOLICY" ) {
      pos = HandlerHelper::parseCachePolicy( line, location, pos );
      db->notificationCollector()->collectionChanged( location );
      if ( !location.update() )
        return failureResponse( "Unable to change cache policy" );
    } else if ( type == "NAME" ) {
      QByteArray newName;
      pos = ImapParser::parseString( line, newName, pos );
      if ( !db->renameLocation( location, location.parentId(), newName ) )
        return failureResponse( "Unable to rename collection" );
    } else if ( type == "PARENT" ) {
      qint64 newParent;
      bool ok = false;
      pos = ImapParser::parseNumber( line, newParent, &ok, pos );
      if ( !ok )
        return failureResponse( "Invalid syntax" );
      if ( !db->renameLocation( location, newParent, location.name() ) )
        return failureResponse( "Unable to reparent colleciton" );
    } else if ( type == "REMOTEID" ) {
      // FIXME: missing change notification
      QString rid;
      pos = ImapParser::parseString( line, rid, pos );
      if ( rid == location.remoteId() )
        continue;
      location.setRemoteId( rid );
      if ( !location.update() )
        return failureResponse( "Unable to change remote identifier" );
    } else if ( type.isEmpty() ) {
      break; // input end
    } else {
      // custom attribute
      bool removeOnly = false;
      if ( type.startsWith( '-' ) ) {
        type = type.mid( 1 );
        removeOnly = true;
      }
      if ( !db->removeCollectionAttribute( location, type ) )
        return failureResponse( "Unable to remove custom collection attribute" );
      if ( ! removeOnly ) {
        QByteArray value;
        pos = ImapParser::parseString( line, value, pos );
        if ( !db->addCollectionAttribute( location, type, value ) )
          return failureResponse( "Unable to add custom collection attribute" );
      }
    }
  }

  if ( !transaction.commit() )
    return failureResponse( "Unable to commit transaction." );

  Response response;
  response.setTag( tag() );
  response.setString( "MODIFY done" );
  emit responseAvailable( response );
  return true;
}


Generated by  Doxygen 1.6.0   Back to index