2 #include "kmacctmaildir.h"
3 #include <config-kmail.h>
4 #include "kmfoldermaildir.h"
5 #include "kmacctfolder.h"
6 #include "broadcaststatus.h"
7 using KPIM::BroadcastStatus
;
8 #include "progressmanager.h"
9 using KPIM::ProgressManager
;
12 #include <kmessagebox.h>
14 #include <kconfiggroup.h>
25 #include <paths.h> /* defines _PATH_MAILDIR */
30 //-----------------------------------------------------------------------------
31 KMAcctMaildir::KMAcctMaildir(AccountManager
* aOwner
, const QString
& aAccountName
, uint id
):
32 KMAccount(aOwner
, aAccountName
, id
)
37 //-----------------------------------------------------------------------------
38 KMAcctMaildir::~KMAcctMaildir()
44 //-----------------------------------------------------------------------------
45 void KMAcctMaildir::init() {
48 mLocation
= qgetenv("MAIL");
49 if (mLocation
.isNull()) {
50 mLocation
= qgetenv("HOME");
51 mLocation
+= "/Maildir/";
56 //-----------------------------------------------------------------------------
57 void KMAcctMaildir::pseudoAssign( const KMAccount
* a
)
59 KMAccount::pseudoAssign( a
);
61 const KMAcctMaildir
* m
= dynamic_cast<const KMAcctMaildir
*>( a
);
64 setLocation( m
->location() );
67 //-----------------------------------------------------------------------------
68 void KMAcctMaildir::processNewMail(bool)
73 if ( precommand().isEmpty() ) {
74 QFileInfo
fi( location() );
76 checkDone( hasNewMail
, CheckOK
);
77 BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( mName
, 0 );
82 KMFolder
mailFolder(0, location(), KMFolderTypeMaildir
,
83 false /* no index */, false /* don't export sernums */);
91 checkDone( hasNewMail
, CheckError
);
92 BroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." ));
96 BroadcastStatus::instance()->setStatusMsg(
97 i18n("Preparing transmission from \"%1\"...", mName
));
99 Q_ASSERT( !mMailCheckProgressItem
);
100 mMailCheckProgressItem
= KPIM::ProgressManager::createProgressItem(
103 i18n("Preparing transmission from \"%1\"...", mName
),
104 false, // cannot be canceled
105 false ); // no tls/ssl
107 // run the precommand
108 if (!runPrecommand(precommand()))
110 kDebug(5006) <<"cannot run precommand" << precommand();
111 checkDone( hasNewMail
, CheckError
);
112 BroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." ));
116 rc
= mailFolder
.open( "acctmaildirMail" );
119 QString aStr
= i18n("<qt>Cannot open folder <b>%1</b>.</qt>", mailFolder
.location() );
120 KMessageBox::sorry(0, aStr
);
121 kDebug(5006) <<"cannot open folder" << mailFolder
.location();
122 checkDone( hasNewMail
, CheckError
);
123 BroadcastStatus::instance()->setStatusMsg( i18n( "Transmission failed." ));
127 mFolder
->open( "acctmaildirFold" );
130 num
= mailFolder
.count();
135 mMailCheckProgressItem
->setTotalItems( num
);
137 for (long i
=0; i
<num
; i
++)
140 if( kmkernel
->mailCheckAborted() ) {
141 BroadcastStatus::instance()->setStatusMsg( i18n("Transmission aborted.") );
147 QString statusMsg
= i18n( "Moving message %1 of %2 from %3.",
148 i
, num
, mailFolder
.location() );
149 mMailCheckProgressItem
->incCompletedItems();
150 mMailCheckProgressItem
->updateProgress();
151 mMailCheckProgressItem
->setStatus( statusMsg
);
153 msg
= mailFolder
.take(0);
156 msg
->setStatus(msg
->headerField("Status").toLatin1(),
157 msg
->headerField("X-Status").toLatin1());
158 if ( !msg
->headerField( "X-KMail-EncryptionState" ).isEmpty() )
159 msg
->setEncryptionStateChar( msg
->headerField( "X-KMail-EncryptionState" ).at(0) );
160 if ( !msg
->headerField( "X-KMail-SignatureState" ).isEmpty() )
161 msg
->setSignatureStateChar( msg
->headerField( "X-KMail-SignatureState" ).at(0));
163 addedOk
= processNewMsg(msg
);
168 if (t
.elapsed() >= 200) { //hardwired constant
169 qApp
->processEvents();
175 if( mMailCheckProgressItem
) { // do this only once...
176 BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( num
);
177 mMailCheckProgressItem
->setStatus(
178 i18np( "Fetched 1 message from maildir folder %2.",
179 "Fetched %1 messages from maildir folder %2.",
180 num
, mailFolder
.location() ) );
182 mMailCheckProgressItem
->setComplete();
183 mMailCheckProgressItem
= 0;
187 BroadcastStatus::instance()->setStatusMsgTransmissionCompleted( mName
, num
);
189 // else warning is written already
191 mailFolder
.close( "acctmaildirMail" );
192 mFolder
->close( "acctmaildirFold" );
194 checkDone( hasNewMail
, CheckOK
);
200 //-----------------------------------------------------------------------------
201 void KMAcctMaildir::readConfig(KConfigGroup
& config
)
203 KMAccount::readConfig(config
);
204 mLocation
= config
.readPathEntry("Location", mLocation
);
208 //-----------------------------------------------------------------------------
209 void KMAcctMaildir::writeConfig(KConfigGroup
& config
)
211 KMAccount::writeConfig(config
);
212 config
.writePathEntry("Location", mLocation
);
215 //-----------------------------------------------------------------------------
216 void KMAcctMaildir::setLocation(const QString
& aLocation
)
218 mLocation
= aLocation
;