kmail
kmacctmaildir.cppGo to the documentation of this file.00001
00002
00003 #ifdef HAVE_CONFIG_H
00004 #include <config.h>
00005 #endif
00006
00007 #include <qfileinfo.h>
00008 #include "kmacctmaildir.h"
00009 #include "kmfoldermaildir.h"
00010 #include "kmacctfolder.h"
00011 #include "broadcaststatus.h"
00012 using KPIM::BroadcastStatus;
00013 #include "progressmanager.h"
00014 using KPIM::ProgressManager;
00015
00016 #include <kapplication.h>
00017 #include <klocale.h>
00018 #include <kmessagebox.h>
00019 #include <kdebug.h>
00020 #include <kconfig.h>
00021
00022 #include <qstylesheet.h>
00023
00024 #include <stdlib.h>
00025 #include <stdio.h>
00026 #include <errno.h>
00027 #include <assert.h>
00028
00029 #ifdef HAVE_PATHS_H
00030 #include <paths.h>
00031 #endif
00032
00033 #undef None
00034
00035
00036 KMAcctMaildir::KMAcctMaildir(AccountManager* aOwner, const QString& aAccountName, uint id):
00037 KMAccount(aOwner, aAccountName, id)
00038 {
00039 }
00040
00041
00042
00043 KMAcctMaildir::~KMAcctMaildir()
00044 {
00045 mLocation = "";
00046 }
00047
00048
00049
00050 QString KMAcctMaildir::type(void) const
00051 {
00052 return "maildir";
00053 }
00054
00055
00056
00057 void KMAcctMaildir::init() {
00058 KMAccount::init();
00059
00060 mLocation = getenv("MAIL");
00061 if (mLocation.isNull()) {
00062 mLocation = getenv("HOME");
00063 mLocation += "/Maildir/";
00064 }
00065 }
00066
00067
00068
00069 void KMAcctMaildir::pseudoAssign( const KMAccount * a )
00070 {
00071 KMAccount::pseudoAssign( a );
00072
00073 const KMAcctMaildir * m = dynamic_cast<const KMAcctMaildir*>( a );
00074 if ( !m ) return;
00075
00076 setLocation( m->location() );
00077 }
00078
00079
00080 void KMAcctMaildir::processNewMail(bool)
00081 {
00082 QTime t;
00083 hasNewMail = false;
00084
00085 if ( precommand().isEmpty() ) {
00086 QFileInfo fi( location() );
00087 if ( !fi.exists() ) {
00088 checkDone( hasNewMail, CheckOK );
00089 BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( mName, 0 );
00090 return;
00091 }
00092 }
00093
00094 KMFolder mailFolder(0, location(), KMFolderTypeMaildir,
00095 false , false );
00096
00097 long num = 0;
00098 long i;
00099 int rc;
00100 KMMessage* msg;
00101 bool addedOk;
00102
00103 if (!mFolder) {
00104 checkDone( hasNewMail, CheckError );
00105 BroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." ));
00106 return;
00107 }
00108
00109 BroadcastStatus::instance()->setStatusMsg(
00110 i18n("Preparing transmission from \"%1\"...").arg(mName));
00111
00112 Q_ASSERT( !mMailCheckProgressItem );
00113 QString escapedName = QStyleSheet::escape( mName );
00114 mMailCheckProgressItem = KPIM::ProgressManager::createProgressItem(
00115 "MailCheck" + mName,
00116 escapedName,
00117 i18n("Preparing transmission from \"%1\"...").arg( escapedName ),
00118 false,
00119 false );
00120
00121
00122 if (!runPrecommand(precommand()))
00123 {
00124 kdDebug(5006) << "cannot run precommand " << precommand() << endl;
00125 checkDone( hasNewMail, CheckError );
00126 BroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." ));
00127 return;
00128 }
00129
00130 rc = mailFolder.open("acctmaildirMail");
00131 if (rc)
00132 {
00133 QString aStr = i18n("<qt>Cannot open folder <b>%1</b>.</qt>").arg( mailFolder.location() );
00134 KMessageBox::sorry(0, aStr);
00135 kdDebug(5006) << "cannot open folder " << mailFolder.location() << endl;
00136 checkDone( hasNewMail, CheckError );
00137 BroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." ));
00138 return;
00139 }
00140
00141 mFolder->open("acctmaildirFold");
00142
00143
00144 num = mailFolder.count();
00145
00146 addedOk = true;
00147 t.start();
00148
00149
00150 QString statusMsgStub = i18n("Moving message %3 of %2 from %1.")
00151 .arg(mailFolder.location()).arg(num);
00152
00153 mMailCheckProgressItem->setTotalItems( num );
00154
00155 for (i=0; i<num; i++)
00156 {
00157
00158 if( kmkernel->mailCheckAborted() ) {
00159 BroadcastStatus::instance()->setStatusMsg( i18n("Transmission aborted.") );
00160 num = i;
00161 addedOk = false;
00162 }
00163 if (!addedOk) break;
00164
00165 QString statusMsg = statusMsgStub.arg(i);
00166 mMailCheckProgressItem->incCompletedItems();
00167 mMailCheckProgressItem->updateProgress();
00168 mMailCheckProgressItem->setStatus( statusMsg );
00169
00170 msg = mailFolder.take(0);
00171 if (msg)
00172 {
00173 msg->setStatus(msg->headerField("Status").latin1(),
00174 msg->headerField("X-Status").latin1());
00175 msg->setEncryptionStateChar( msg->headerField( "X-KMail-EncryptionState" ).at(0));
00176 msg->setSignatureStateChar( msg->headerField( "X-KMail-SignatureState" ).at(0));
00177
00178 addedOk = processNewMsg(msg);
00179 if (addedOk)
00180 hasNewMail = true;
00181 }
00182
00183 if (t.elapsed() >= 200) {
00184 kapp->processEvents();
00185 t.start();
00186 }
00187
00188 }
00189
00190 if( mMailCheckProgressItem ) {
00191 BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( num );
00192 mMailCheckProgressItem->setStatus(
00193 i18n( "Fetched 1 message from maildir folder %1.",
00194 "Fetched %n messages from maildir folder %1.",
00195 num ).arg(mailFolder.location() ) );
00196
00197 mMailCheckProgressItem->setComplete();
00198 mMailCheckProgressItem = 0;
00199 }
00200 if (addedOk)
00201 {
00202 BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( mName, num );
00203 }
00204
00205
00206 mailFolder.close("acctmaildirMail");
00207 mFolder->close("acctmaildirFold");
00208
00209 checkDone( hasNewMail, CheckOK );
00210
00211 return;
00212 }
00213
00214
00215
00216 void KMAcctMaildir::readConfig(KConfig& config)
00217 {
00218 KMAccount::readConfig(config);
00219 mLocation = config.readPathEntry("Location", mLocation);
00220 }
00221
00222
00223
00224 void KMAcctMaildir::writeConfig(KConfig& config)
00225 {
00226 KMAccount::writeConfig(config);
00227 config.writePathEntry("Location", mLocation);
00228 }
00229
00230
00231 void KMAcctMaildir::setLocation(const QString& aLocation)
00232 {
00233 mLocation = aLocation;
00234 }
|