コード例 #1
0
ファイル: kmfolder.cpp プロジェクト: kthxbyte/KDE1-Linaro
//-----------------------------------------------------------------------------
KMMessage* KMFolder::take(int idx)
{
  KMMsgBase* mb;
  KMMessage* msg;

  assert(mStream!=NULL);
  assert(idx>=0 && idx<=mMsgList.high());

  mb = mMsgList[idx];
  if (!mb) return NULL;
  if (!mb->isMessage()) readMsg(idx);

  msg = (KMMessage*)mMsgList.take(idx);
  if (msg->status()==KMMsgStatusUnread ||
	  msg->status()==KMMsgStatusNew) {
	--unreadMsgs;
	emit numUnreadMsgsChanged( this );
  }
  msg->setParent(NULL);
  mDirty = TRUE;
  needsCompact=true; // message is taken from here - needs to be compacted
  if (!mQuiet) emit msgRemoved(idx);

  return msg;
}
コード例 #2
0
ファイル: kmfolder.cpp プロジェクト: kthxbyte/KDE1-Linaro
//-----------------------------------------------------------------------------
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;
}
コード例 #3
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;
}
コード例 #4
0
ファイル: kmsender.cpp プロジェクト: serghei/kde3-kdepim
//-----------------------------------------------------------------------------
void KMSender::outboxMsgAdded(int idx)
{
    ++mTotalMessages;
    KMMsgBase *msg = kmkernel->outboxFolder()->getMsgBase(idx);
    Q_ASSERT(msg);
    if(msg)
        mTotalBytes += msg->msgSize();
}
コード例 #5
0
void StorageModel::fillMessageItemThreadingData( Core::MessageItem * mi, int row, ThreadingDataSubset subset ) const
{
  KMMsgBase * msg = mFolder->getMsgBase( row );
  Q_ASSERT( msg ); // We ASSUME that initializeMessageItem has been called successfully...

  switch ( subset )
  {
    case PerfectThreadingReferencesAndSubject:
      mi->setStrippedSubjectMD5( msg->strippedSubjectMD5() );
      if ( mi->strippedSubjectMD5().isEmpty() )
      {
        msg->initStrippedSubjectMD5();
        mi->setStrippedSubjectMD5( msg->strippedSubjectMD5() );
      }
      mi->setSubjectIsPrefixed( msg->subjectIsPrefixed() && !msg->subject().isEmpty() );
    // fall through
    case PerfectThreadingPlusReferences:
      mi->setReferencesIdMD5( msg->replyToAuxIdMD5() );
    // fall through
    case PerfectThreadingOnly:
      mi->setMessageIdMD5( msg->msgIdMD5() );
      mi->setInReplyToIdMD5( msg->replyToIdMD5() );
    break;
    default:
      Q_ASSERT( false ); // should never happen
    break;
  };  
}
コード例 #6
0
ファイル: kmfiltermgr.cpp プロジェクト: serghei/kde3-kdepim
int KMFilterMgr::process(Q_UINT32 serNum, const KMFilter *filter)
{
    bool stopIt = false;
    int result = 1;

    if(!filter)
        return 1;

    if(isMatching(serNum, filter))
    {
        KMFolder *folder = 0;
        int idx = -1;
        // get the message with the serNum
        KMMsgDict::instance()->getLocation(serNum, &folder, &idx);
        if(!folder || (idx == -1) || (idx >= folder->count()))
        {
            return 1;
        }
        KMFolderOpener openFolder(folder, "filtermgr");
        KMMsgBase *msgBase = folder->getMsgBase(idx);
        bool unGet = !msgBase->isMessage();
        KMMessage *msg = folder->getMsg(idx);
        // do the actual filtering stuff
        if(!msg || !beginFiltering(msg))
        {
            if(unGet)
                folder->unGetMsg(idx);
            return 1;
        }
        if(filter->execActions(msg, stopIt) == KMFilter::CriticalError)
        {
            if(unGet)
                folder->unGetMsg(idx);
            return 2;
        }

        KMFolder *targetFolder = MessageProperty::filterFolder(msg);

        endFiltering(msg);
        if(targetFolder)
        {
            tempOpenFolder(targetFolder);
            msg->setTransferInProgress(false);
            result = targetFolder->moveMsg(msg);
            msg->setTransferInProgress(true);
        }
        if(unGet)
            folder->unGetMsg(idx);
    }
    else
    {
        result = 1;
    }
    return result;
}
コード例 #7
0
void StorageModel::setMessageItemStatus( Core::MessageItem * mi, int row, const KPIM::MessageStatus &status )
{
  Q_UNUSED( row );

  KMMsgBase * msg = msgBase( mi );
  if ( !msg )
    return; // This can be called at a really later stage (with respect to the initial fill).
            // Assume that something wrong may be happened to the folder in the meantime...

  msg->setStatus( status );
}
コード例 #8
0
ファイル: kmfolder.cpp プロジェクト: kthxbyte/KDE1-Linaro
//-----------------------------------------------------------------------------
KMMessage* KMFolder::getMsg(int idx)
{
  KMMsgBase* mb;

  // assert(idx>=0 && idx<=mMsgList.high());
  if(!(idx >= 0 && idx <= mMsgList.high()))
    return 0L;

  mb = mMsgList[idx];
  if (!mb) return NULL;

  if (mb->isMessage()) return ((KMMessage*)mb);
  return readMsg(idx);
}
コード例 #9
0
ファイル: kmfolder.cpp プロジェクト: kthxbyte/KDE1-Linaro
//-----------------------------------------------------------------------------
void KMFolder::markNewAsUnread(void)
{
  KMMsgBase* msgBase;
  int i;

  for (i=0; i<mMsgList.high(); i++)
  {
    if (!(msgBase = mMsgList[i])) continue;
    if (msgBase->status() == KMMsgStatusNew)
    {
      msgBase->setStatus(KMMsgStatusUnread);
      msgBase->setDirty(TRUE);
    }
  }
}
コード例 #10
0
// Profiling note: About 30% of the time taken to initialize the
// listview is spent in this function. About 60% is spent in operator
// new and QListViewItem::QListViewItem.
void HeaderItem::irefresh()
{
  KMHeaders *headers = static_cast<KMHeaders*>(listView());
  NestingPolicy threadingPolicy = headers->getNestingPolicy();
  if ((threadingPolicy == AlwaysOpen) ||
      (threadingPolicy == DefaultOpen)) {
    //Avoid opening items as QListView is currently slow to do so.
    setOpen(true);
    return;

  }
  if (threadingPolicy == DefaultClosed)
    return; //default to closed

  // otherwise threadingPolicy == OpenUnread
  if (parent() && parent()->isOpen()) {
    setOpen(true);
    return;
  }

  KMMsgBase *mMsgBase = headers->folder()->getMsgBase( mMsgId );
  mSerNum = mMsgBase->getMsgSerNum();
  if (mMsgBase->isNew() || mMsgBase->isUnread()
      || mMsgBase->isImportant() || mMsgBase->isTodo() || mMsgBase->isWatched() ) {
    setOpen(true);
    HeaderItem * topOfThread = this;
    while(topOfThread->parent())
      topOfThread = (HeaderItem*)topOfThread->parent();
    topOfThread->setOpenRecursive(true);
  }
}
コード例 #11
0
void StorageModel::updateMessageItemData( Core::MessageItem * mi, int row ) const
{
  KMMsgBase * msg = mFolder->getMsgBase( row );
  Q_ASSERT( msg ); // We ASSUME that initializeMessageItem has been called successfully...

  bool dateDiffers = mi->date() != msg->date();

  if ( dateDiffers )
  {
    mi->setDate( msg->date() );
    mi->recomputeMaxDate();
  }

  KPIM::MessageStatus stat = msg->messageStatus();

  mi->setStatus( stat );

  setMessageItemData( mi, msg );

  // FIXME: Handle MDN State ?
}
コード例 #12
0
QString HeaderItem::text( int col) const
{
  KMHeaders *headers = static_cast<KMHeaders*>(listView());
  KMMsgBase *mMsgBase = headers->folder()->getMsgBase( mMsgId );
  QString tmp;

  if ( !mMsgBase )
    return QString();

  if ( col == headers->paintInfo()->senderCol ) {
    if ( (headers->folder()->whoField().lower() == "to") && !headers->paintInfo()->showReceiver )
      tmp = mMsgBase->toStrip();
    else
      tmp = mMsgBase->fromStrip();
    if (tmp.isEmpty())
      tmp = i18n("Unknown");
    else
      tmp = tmp.simplifyWhiteSpace();

  } else if ( col == headers->paintInfo()->receiverCol ) {
    tmp = mMsgBase->toStrip();
    if (tmp.isEmpty())
      tmp = i18n("Unknown");
    else
      tmp = tmp.simplifyWhiteSpace();

  } else if(col == headers->paintInfo()->subCol) {
    tmp = mMsgBase->subject();
    if (tmp.isEmpty())
      tmp = i18n("No Subject");
    else
      tmp.remove(QRegExp("[\r\n]"));

  } else if(col == headers->paintInfo()->dateCol) {
    tmp = headers->mDate.dateString( mMsgBase->date() );
  } else if(col == headers->paintInfo()->sizeCol
      && headers->paintInfo()->showSize) {
    if ( mMsgBase->parent()->folderType() == KMFolderTypeImap ) {
      tmp = KIO::convertSize( mMsgBase->msgSizeServer() );
    } else {
      tmp = KIO::convertSize( mMsgBase->msgSize() );
    }
  }
  return tmp;
}
コード例 #13
0
bool StorageModel::initializeMessageItem( Core::MessageItem * mi, int row, bool bUseReceiver ) const
{
  KMMsgBase * msg = mFolder->getMsgBase( row );
  if ( !msg )
    return false;

  QString sender = msg->fromStrip();
  QString receiver = msg->toStrip();

  // Static for speed reasons
  static const QString noSubject = i18nc( "displayed as subject when the subject of a mail is empty", "No Subject" );
  static const QString unknown( i18nc( "displayed when a mail has unknown sender, receiver or date", "Unknown" ) );

  if ( sender.isEmpty() )
    sender = unknown;
  if ( receiver.isEmpty() )
    receiver = unknown;

  mi->initialSetup(
      msg->date(),
      mFolder->folderType() == KMFolderTypeImap ? msg->msgSizeServer() : msg->msgSize(),
      sender, receiver,
      bUseReceiver ? receiver : sender
    );

  mi->setUniqueId( msg->getMsgSerNum() );

  KPIM::MessageStatus stat = msg->messageStatus();

  QString subject = msg->subject();
  if ( subject.isEmpty() )
    subject = '(' + noSubject + ')';
  mi->setSubjectAndStatus( subject, stat );

  setMessageItemData( mi, msg );

  return true;
}
コード例 #14
0
void HeaderItem::paintCell( QPainter * p, const QColorGroup & cg,
    int column, int width, int align )
{
  KMHeaders *headers = static_cast<KMHeaders*>(listView());
  if (headers->noRepaint) return;
  if (!headers->folder()) return;
  KMMsgBase *mMsgBase = headers->folder()->getMsgBase( mMsgId );
  if (!mMsgBase) return;

  QColorGroup _cg( cg );
  QColor c = _cg.text();
  QColor *color = const_cast<QColor *>( &headers->paintInfo()->colFore );
  QFont font = p->font();
  int weight = font.weight();

  // for color and font family "important" overrides "new" overrides "unread"
  // overrides "todo" for the weight we use the maximal weight
  if ( mMsgBase->isTodo() ) {
    color = const_cast<QColor*>( &headers->paintInfo()->colTodo );
    font = headers->todoFont();
    weight = QMAX( weight, font.weight() );
  }
  if ( mMsgBase->isUnread() ) {
    color = const_cast<QColor*>( &headers->paintInfo()->colUnread );
    font = headers->unreadFont();
    weight = QMAX( weight, font.weight() );
  }
  if ( mMsgBase->isNew() ) {
    color = const_cast<QColor*>( &headers->paintInfo()->colNew );
    font = headers->newFont();
    weight = QMAX( weight, font.weight() );
  }

  if ( mMsgBase->isImportant() ) {
    color = const_cast<QColor*>( &headers->paintInfo()->colFlag );
    font = headers->importantFont();
    weight = QMAX( weight, font.weight() );
  }
  if ( column == headers->paintInfo()->dateCol ) {
    font = headers->dateFont();
  }

  QColor cdisabled = KGlobalSettings::inactiveTextColor();
  if ( headers->isMessageCut( msgSerNum() ) ) {
    font.setItalic( true );
    color = &cdisabled;
  }

  // set color and font
  _cg.setColor( QColorGroup::Text, *color );
  font.setWeight( weight );
  p->setFont( font );

  KListViewItem::paintCell( p, _cg, column, width, align );

  if (aboutToBeDeleted()) {
    // strike through
    p->drawLine( 0, height()/2, width, height()/2);
  }

  // reset color
  _cg.setColor( QColorGroup::Text, c );
}
コード例 #15
0
const QPixmap *HeaderItem::pixmap(int col) const
{
  KMHeaders *headers = static_cast<KMHeaders*>(listView());
  KMMsgBase *msgBase = headers->folder()->getMsgBase( mMsgId );

  if ( col == headers->paintInfo()->subCol ) {

    PixmapList pixmaps;

    if ( !headers->mPaintInfo.showSpamHam ) {
      // Have the spam/ham and watched/ignored icons first, I guess.
      if ( msgBase->isSpam() ) pixmaps << *KMHeaders::pixSpam;
      if ( msgBase->isHam()  ) pixmaps << *KMHeaders::pixHam;
    }

    if ( !headers->mPaintInfo.showWatchedIgnored ) {
      if ( msgBase->isIgnored() ) pixmaps << *KMHeaders::pixIgnored;
      if ( msgBase->isWatched() ) pixmaps << *KMHeaders::pixWatched;
    }

    if ( !headers->mPaintInfo.showStatus ) {
      const QPixmap *pix = statusIcon(msgBase);
      if ( pix ) pixmaps << *pix;
    }

    // Only merge the attachment icon in if that is configured.
    if ( headers->paintInfo()->showAttachmentIcon &&
        !headers->paintInfo()->showAttachment &&
        msgBase->attachmentState() == KMMsgHasAttachment )
      pixmaps << *KMHeaders::pixAttachment;

    // Only merge the crypto icons in if that is configured.
    if ( headers->paintInfo()->showCryptoIcons ) {
      const QPixmap *pix;

      if ( !headers->paintInfo()->showCrypto )
        if ( (pix = cryptoIcon(msgBase))    ) pixmaps << *pix;

      if ( !headers->paintInfo()->showSigned )
        if ( (pix = signatureIcon(msgBase)) ) pixmaps << *pix;
    }

    if ( !headers->mPaintInfo.showImportant )
      if ( msgBase->isImportant() ) pixmaps << *KMHeaders::pixFlag;

    if ( !headers->mPaintInfo.showTodo )
      if ( msgBase->isTodo() ) pixmaps << *KMHeaders::pixTodo;

    static QPixmap mergedpix;
    mergedpix = pixmapMerge( pixmaps );
    return &mergedpix;
  }
  else if ( col == headers->paintInfo()->statusCol ) {
    return statusIcon(msgBase);
  }
  else if ( col == headers->paintInfo()->attachmentCol ) {
    if ( msgBase->attachmentState() == KMMsgHasAttachment )
      return KMHeaders::pixAttachment;
  }
  else if ( col == headers->paintInfo()->importantCol ) {
    if ( msgBase->isImportant() )
      return KMHeaders::pixFlag;
  }
  else if ( col == headers->paintInfo()->todoCol ) {
    if ( msgBase->isTodo() )
      return KMHeaders::pixTodo;
  }
  else if ( col == headers->paintInfo()->spamHamCol ) {
    if ( msgBase->isSpam() ) return KMHeaders::pixSpam;
    if ( msgBase->isHam()  ) return KMHeaders::pixHam;
  }
  else if ( col == headers->paintInfo()->watchedIgnoredCol ) {
    if ( msgBase->isWatched() ) return KMHeaders::pixWatched;
    if ( msgBase->isIgnored() ) return KMHeaders::pixIgnored;
  }
  else if ( col == headers->paintInfo()->signedCol ) {
    return signatureIcon(msgBase);
  }
  else if ( col == headers->paintInfo()->cryptoCol ) {
    return cryptoIcon(msgBase);
  }
  return 0;
}