kmail Library API Documentation

maildirjob.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 #ifdef HAVE_CONFIG_H
00031 #include <config.h>
00032 #endif
00033 
00034 #include "maildirjob.h"
00035 
00036 #include "kmfoldermaildir.h"
00037 
00038 #include <kapplication.h>
00039 #include <kdebug.h>
00040 
00041 #include <qtimer.h>
00042 #include <qdatetime.h>
00043 
00044 namespace KMail {
00045 
00046 
00047 //-----------------------------------------------------------------------------
00048 MaildirJob::MaildirJob( KMMessage *msg, JobType jt , KMFolder *folder )
00049   : FolderJob( msg, jt, folder ), mParentFolder( 0 )
00050 {
00051 }
00052 
00053 //-----------------------------------------------------------------------------
00054 MaildirJob::MaildirJob( QPtrList<KMMessage>& msgList, const QString& sets,
00055                         JobType jt , KMFolder *folder )
00056   : FolderJob( msgList, sets, jt, folder ), mParentFolder( 0 )
00057 {
00058 }
00059 
00060 //-----------------------------------------------------------------------------
00061 MaildirJob::~MaildirJob()
00062 {
00063 }
00064 
00065 //-----------------------------------------------------------------------------
00066 void MaildirJob::setParentFolder( const KMFolderMaildir* parent )
00067 {
00068   mParentFolder = const_cast<KMFolderMaildir*>( parent );
00069 }
00070 
00071 
00072 
00073 //-----------------------------------------------------------------------------
00074 void MaildirJob::execute()
00075 {
00076   QTimer::singleShot( 0, this, SLOT(startJob()) );
00077 }
00078 
00079 //-----------------------------------------------------------------------------
00080 void MaildirJob::startJob()
00081 {
00082   switch( mType ) {
00083   case tGetMessage:
00084     {
00085       KMMessage* msg = mMsgList.first();
00086       if ( msg ) {
00087         msg->setComplete( true );
00088         emit messageRetrieved( msg );
00089       }
00090     }
00091     break;
00092   case tDeleteMessage:
00093     {
00094       static_cast<KMFolder*>(mParentFolder)->removeMsg( mMsgList );
00095     }
00096     break;
00097   case tPutMessage:
00098     {
00099       mParentFolder->addMsg(  mMsgList.first() );
00100       emit messageStored( mMsgList.first() );
00101     }
00102     break;
00103   case tExpireMessages:
00104     {
00105       expireMessages();
00106     }
00107     break;
00108   case tCopyMessage:
00109   case tCreateFolder:
00110   case tGetFolder:
00111   case tListDirectory:
00112     kdDebug(5006)<<k_funcinfo<<"### Serious problem! "<<endl;
00113     break;
00114   default:
00115     break;
00116   }
00117   //OK, we're done
00118   //delete this;
00119   deleteLater();
00120 }
00121 
00122 void
00123 MaildirJob::expireMessages()
00124 {
00125   int              days             = 0;
00126   int              maxUnreadTime    = 0;
00127   int              maxReadTime      = 0;
00128   const KMMsgBase *mb               = 0;
00129   QValueList<int>  rmvMsgList;
00130   int              i                = 0;
00131   time_t           msgTime, maxTime = 0;
00132   QTime            t;
00133 
00134   days = mParentFolder->daysToExpire( mParentFolder->getUnreadExpireAge(),
00135                                       mParentFolder->getUnreadExpireUnits() );
00136   if (days > 0) {
00137     kdDebug(5006) << "deleting unread older than "<< days << " days" << endl;
00138     maxUnreadTime = time(0) - days * 3600 * 24;
00139   }
00140 
00141   days = mParentFolder->daysToExpire( mParentFolder->getReadExpireAge(),
00142                                       mParentFolder->getReadExpireUnits() );
00143   if (days > 0) {
00144     kdDebug(5006) << "deleting read older than "<< days << " days" << endl;
00145     maxReadTime = time(0) - days * 3600 * 24;
00146   }
00147 
00148   if ((maxUnreadTime == 0) && (maxReadTime == 0)) {
00149     return;
00150   }
00151 
00152   t.start();
00153   mParentFolder->open();
00154   for( i=mParentFolder->count()-1; i>=0; i-- ) {
00155     mb = mParentFolder->getMsgBase(i);
00156     if (mb == 0) {
00157       continue;
00158     }
00159     msgTime = mb->date();
00160 
00161     if (mb->isUnread()) {
00162       maxTime = maxUnreadTime;
00163     } else {
00164       maxTime = maxReadTime;
00165     }
00166 
00167     if (msgTime < maxTime) {
00168       mParentFolder->removeMsg( i );
00169     }
00170     if ( t.elapsed() >= 150 ) {
00171       kapp->processEvents();
00172       t.restart();
00173     }
00174   }
00175   mParentFolder->close();
00176 
00177   return;
00178 }
00179 
00180 }
00181 
00182 #include "maildirjob.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