Пример #1
0
//-----------------------------------------------------------------------------
int KMFolder::writeIndex(void)
{
  KMMsgBase* msgBase;
  int old_umask;
  int i=0;

  if (mIndexStream) fclose(mIndexStream);
  old_umask = umask(077);
  mIndexStream = fopen(indexLocation(), "w");
  umask(old_umask);
  if (!mIndexStream) return errno;

  fprintf(mIndexStream, "# KMail-Index V%d\n", INDEX_VERSION);

  mHeaderOffset = ftell(mIndexStream);
  for (i=0; i<mMsgList.high(); i++)
  {
    if (!(msgBase = mMsgList[i])) continue;
    fprintf(mIndexStream, "%s\n", (const char*)msgBase->asIndexString());
  }
  fflush(mIndexStream);

  mDirty = FALSE;
  return 0;
}
Пример #2
0
int KMFolderIndex::writeMessages( KMMsgBase* msg, bool flush, FILE* indexStream )
{
  const uint high = mMsgList.high();
  for ( uint i = 0; i < high || msg; i++ )
  {
    KMMsgBase* msgBase = msg ? msg : mMsgList.at(i);
    if ( !msgBase )
      continue;
    int len;
    const uchar *buffer = msgBase->asIndexString( len );
    if ( fwrite( &len, sizeof( len ), 1, indexStream ) != 1 )
      return 1;
    off_t offset = KDE_ftell( indexStream );
    msgBase->setIndexOffset( offset );
    msgBase->setIndexLength( len );
    if ( fwrite( buffer, len, 1, indexStream ) != 1 ) {
      kDebug() << "Whoa!";
      return 1;
    }
    if ( msg )
      break; // only one
  }
  if ( flush )
    fflush( indexStream );
  int error = ferror( indexStream );
  if ( error != 0 )
    return error;
  return 0;
}