kmail Library API Documentation

mboxjob.cpp

00001 /*  -*- mode: C++; c-file-style: "gnu" -*-
00002  *
00003  *  This file is part of KMail, the KDE mail client.
00004  *  Copyright (c) 2003 Zack Rusin <zack@kde.org>
00005  *
00006  *  KMail is free software; you can redistribute it and/or modify it
00007  *  under the terms of the GNU General Public License, version 2, as
00008  *  published by the Free Software Foundation.
00009  *
00010  *  KMail is distributed in the hope that it will be useful, but
00011  *  WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  *  General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018  *
00019  *  In addition, as a special exception, the copyright holders give
00020  *  permission to link the code of this program with any edition of
00021  *  the Qt library by Trolltech AS, Norway (or with modified versions
00022  *  of Qt that use the same license as Qt), and distribute linked
00023  *  combinations including the two.  You must obey the GNU General
00024  *  Public License in all respects for all of the code used other than
00025  *  Qt.  If you modify this file, you may extend this exception to
00026  *  your version of the file, but you are not obligated to do so.  If
00027  *  you do not wish to do so, delete this exception statement from
00028  *  your version.
00029  */
00030 
00031 #ifdef HAVE_CONFIG_H
00032 #include <config.h>
00033 #endif
00034 
00035 #include "mboxjob.h"
00036 
00037 #include "kmfoldermbox.h"
00038 
00039 #include <kapplication.h>
00040 #include <kdebug.h>
00041 #include <qtimer.h>
00042 #include <qdatetime.h>
00043 
00044 namespace KMail {
00045 
00046 
00047 //-----------------------------------------------------------------------------
00048 MboxJob::MboxJob( KMMessage *msg, JobType jt , KMFolder *folder  )
00049   : FolderJob( msg, jt, folder )
00050 {
00051 }
00052 
00053 //-----------------------------------------------------------------------------
00054 MboxJob::MboxJob( QPtrList<KMMessage>& msgList, const QString& sets,
00055                   JobType jt, KMFolder *folder  )
00056   : FolderJob( msgList, sets, jt, folder )
00057 {
00058 }
00059 
00060 //-----------------------------------------------------------------------------
00061 MboxJob::~MboxJob()
00062 {
00063 }
00064 
00065 //-----------------------------------------------------------------------------
00066 void
00067 MboxJob::execute()
00068 {
00069   QTimer::singleShot( 0, this, SLOT(startJob()) );
00070 }
00071 
00072 
00073 //-----------------------------------------------------------------------------
00074 void
00075 MboxJob::expireMessages()
00076 {
00077   int              days             = 0;
00078   int              maxUnreadTime    = 0;
00079   int              maxReadTime      = 0;
00080   const KMMsgBase *mb               = 0;
00081   QValueList<int>  rmvMsgList;
00082   int              i                = 0;
00083   time_t           msgTime, maxTime = 0;
00084   QTime            t;
00085 
00086   days = mParent->daysToExpire( mParent->getUnreadExpireAge(),
00087                                 mParent->getUnreadExpireUnits() );
00088   if (days > 0) {
00089     kdDebug(5006) << "deleting unread older than "<< days << " days" << endl;
00090     maxUnreadTime = time(0) - days * 3600 * 24;
00091   }
00092 
00093   days = mParent->daysToExpire( mParent->getReadExpireAge(),
00094                                 mParent->getReadExpireUnits() );
00095   if (days > 0) {
00096     kdDebug(5006) << "deleting read older than "<< days << " days" << endl;
00097     maxReadTime = time(0) - days * 3600 * 24;
00098   }
00099 
00100   if ((maxUnreadTime == 0) && (maxReadTime == 0)) {
00101     return;
00102   }
00103 
00104   t.start();
00105   mParent->open();
00106   for( i=mParent->count()-1; i>=0; i-- ) {
00107     mb = mParent->getMsgBase(i);
00108     if (mb == 0) {
00109       continue;
00110     }
00111     msgTime = mb->date();
00112 
00113     if (mb->isUnread()) {
00114       maxTime = maxUnreadTime;
00115     } else {
00116       maxTime = maxReadTime;
00117     }
00118 
00119     if (msgTime < maxTime) {
00120       mParent->removeMsg( i );
00121     }
00122     if ( t.elapsed() >= 150 ) {
00123       kapp->processEvents();
00124       t.restart();
00125     }
00126   }
00127   mParent->close();
00128 
00129   return;
00130 }
00131 
00132 //-----------------------------------------------------------------------------
00133 void
00134 MboxJob::setParent( const KMFolderMbox *parent )
00135 {
00136   mParent = const_cast<KMFolderMbox*>( parent );
00137 }
00138 
00139 //-----------------------------------------------------------------------------
00140 void
00141 MboxJob::startJob()
00142 {
00143   KMMessage *msg = mMsgList.first();
00144   assert( (msg && ( mParent || msg->parent() )) || ( mParent && mType == tExpireMessages) );
00145   switch( mType ) {
00146   case tGetMessage:
00147     {
00148       kdDebug(5006)<<msg<<endl;
00149       kdDebug(5006)<<this<<endl;
00150       kdDebug(5006)<<"Done"<<endl;
00151       //KMMessage* msg = mParent->getMsg( mParent->find( mMsgList.first() ) );
00152       msg->setComplete( true );
00153       emit messageRetrieved( msg );
00154     }
00155     break;
00156   case tDeleteMessage:
00157     {
00158       mParent->removeMsg( mMsgList );
00159     }
00160     break;
00161   case tPutMessage:
00162     {
00163       mParent->addMsg(  mMsgList.first() );
00164       emit messageStored( mMsgList.first() );
00165     }
00166     break;
00167   case tExpireMessages:
00168     {
00169       expireMessages();
00170     }
00171     break;
00172   case tCopyMessage:
00173   case tCreateFolder:
00174   case tGetFolder:
00175   case tListDirectory:
00176     kdDebug(5006)<<k_funcinfo<<"### Serious problem! "<<endl;
00177     break;
00178   default:
00179     break;
00180   }
00181   //OK, we're done
00182   //delete this;
00183   deleteLater();
00184 }
00185 
00186 }
00187 
00188 #include "mboxjob.moc"
KDE Logo
This file is part of the documentation for kmail Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat May 1 11:37:34 2004 by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2003