10 #include <weaverlogger.h>
12 #include "globalsettings.h"
13 #include "broadcaststatus.h"
14 using KPIM::BroadcastStatus;
15 #include "kmstartup.h"
17 #include "kmmainwin.h"
19 #include "kmmsgpart.h"
20 #include "kmreadermainwin.h"
21 #include "kmfoldermgr.h"
22 #include "kmfoldercachedimap.h"
23 #include "kmacctcachedimap.h"
24 #include "kmfiltermgr.h"
25 #include "kmfilteraction.h"
26 #include "kmheaders.h"
27 #define REALLY_WANT_KMSENDER
29 #undef REALLY_WANT_KMSENDER
30 #include "undostack.h"
31 #include "accountmanager.h"
33 #include <libkdepim/kfileio.h>
34 #include "kmversion.h"
35 #include "kmreaderwin.h"
36 #include "kmmainwidget.h"
37 #include "kmfoldertree.h"
38 #include "recentaddresses.h"
39 using KRecentAddress::RecentAddresses;
40 #include "kmmsgdict.h"
41 #include <libkpimidentities/identity.h>
42 #include <libkpimidentities/identitymanager.h>
43 #include "configuredialog.h"
44 #include "kmcommands.h"
45 #include "kmsystemtray.h"
46 #include "transportmanager.h"
47 #include "importarchivedialog.h"
50 #include "kmailicalifaceimpl.h"
51 #include "mailserviceimpl.h"
52 using KMail::MailServiceImpl;
53 #include "mailcomposerIface.h"
54 #include "folderIface.h"
55 using KMail::FolderIface;
56 #include "jobscheduler.h"
57 #include "templateparser.h"
59 #include <kapplication.h>
60 #include <kmessagebox.h>
61 #include <knotifyclient.h>
62 #include <kstaticdeleter.h>
63 #include <kstandarddirs.h>
65 #include <kprogress.h>
66 #include <kpassivepopup.h>
67 #include <dcopclient.h>
68 #include <ksystemtray.h>
71 #include <kio/netaccess.h>
73 using KWallet::Wallet;
74 #include "actionscheduler.h"
76 #include <qutf7codec.h>
79 #include <tqwidgetlist.h>
80 #include <tqobjectlist.h>
82 #include <sys/types.h>
92 #include <kcmdlineargs.h>
93 #include <kstartupinfo.h>
96 static bool s_askingToGoOnline =
false;
101 KMKernel::KMKernel (TQObject *parent,
const char *name) :
102 DCOPObject(
"KMailIface"), TQObject(parent, name),
103 mIdentityManager(0), mConfigureDialog(0),
104 mContextMenuShown( false ), mWallet( 0 )
106 kdDebug(5006) <<
"KMKernel::KMKernel" << endl;
108 the_startingUp =
true;
109 closed_by_user =
true;
110 the_firstInstance =
true;
114 the_outboxFolder = 0;
117 the_draftsFolder = 0;
118 the_templatesFolder = 0;
121 the_imapFolderMgr = 0;
122 the_dimapFolderMgr = 0;
123 the_searchFolderMgr = 0;
127 the_popFilterMgr = 0;
128 the_filterActionDict = 0;
131 mMailCheckAborted =
false;
138 GlobalSettings::self();
151 if ( !TQTextCodec::codecForName(
"utf-7") ) {
152 kdDebug(5006) <<
"No TQt-native utf-7 codec found; registering TQUtf7Codec from libkdenetwork" << endl;
153 (void)
new TQUtf7Codec();
159 if ( TQCString(TQTextCodec::codecForLocale()->name()).lower() ==
"eucjp" )
161 netCodec = TQTextCodec::codecForName(
"jis7");
166 netCodec = TQTextCodec::codecForLocale();
168 mMailService =
new MailServiceImpl();
170 connectDCOPSignal( 0, 0,
"kmailSelectFolder(TQString)",
171 "selectFolder(TQString)",
false );
174 KMKernel::~KMKernel ()
176 TQMap<KIO::Job*, putData>::Iterator it = mPutJobs.begin();
177 while ( it != mPutJobs.end() )
179 KIO::Job *job = it.key();
180 mPutJobs.remove( it );
182 it = mPutJobs.begin();
194 kdDebug(5006) <<
"KMKernel::~KMKernel" << endl;
199 TQString to, cc, bcc, subj, body;
200 QCStringList customHeaders;
202 KURL::List attachURLs;
205 bool viewOnly =
false;
206 bool calledWithSession =
false;
209 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
210 if (!args->getOption(
"subject").isNull())
212 subj = TQString::fromLocal8Bit(args->getOption(
"subject"));
220 if ( subj ==
"ession" ) {
222 calledWithSession =
true;
228 if (!args->getOption(
"cc").isNull())
231 cc = TQString::fromLocal8Bit(args->getOption(
"cc"));
234 if (!args->getOption(
"bcc").isNull())
237 bcc = TQString::fromLocal8Bit(args->getOption(
"bcc"));
240 if (!args->getOption(
"msg").isNull())
243 messageFile.setPath( TQString::fromLocal8Bit(args->getOption(
"msg")) );
246 if (!args->getOption(
"body").isNull())
249 body = TQString::fromLocal8Bit(args->getOption(
"body"));
252 QCStringList attachList = args->getOptionList(
"attach");
253 if (!attachList.isEmpty())
256 for ( QCStringList::Iterator it = attachList.begin() ; it != attachList.end() ; ++it )
257 if ( !(*it).isEmpty() )
258 attachURLs += KURL( TQString::fromLocal8Bit( *it ) );
261 customHeaders = args->getOptionList(
"header");
263 if (args->isSet(
"composer"))
266 if (args->isSet(
"check"))
269 if ( !args->getOption(
"view" ).isNull() ) {
271 const TQString filename =
272 TQString::fromLocal8Bit( args->getOption(
"view" ) );
273 messageFile = KURL::fromPathOrURL( filename );
274 if ( !messageFile.isValid() ) {
275 messageFile = KURL();
276 messageFile.setPath( filename );
280 if ( !calledWithSession ) {
283 for(
int i= 0; i < args->count(); i++)
285 if (strncasecmp(args->arg(i),
"mailto:",7)==0)
286 to += args->url(i).path() +
", ";
288 TQString tmpArg = TQString::fromLocal8Bit( args->arg(i) );
297 if ( !to.isEmpty() ) {
299 to.truncate( to.length() - 2 );
303 if ( !calledWithSession )
306 if ( !noArgsOpensReader && !mailto && !checkMail && !viewOnly )
310 viewMessage( messageFile );
312 action( mailto, checkMail, to, cc, bcc, subj, body, messageFile,
313 attachURLs, customHeaders );
322 if ( !kmkernel->askToGoOnline() )
324 kmkernel->acctMgr()->checkMail(
false);
327 TQStringList KMKernel::accounts()
329 if( kmkernel->acctMgr() )
330 return kmkernel->acctMgr()->getAccounts();
331 return TQStringList();
334 void KMKernel::checkAccount (
const TQString &account)
336 kdDebug(5006) <<
"KMKernel::checkMail called" << endl;
338 KMAccount* acct = kmkernel->acctMgr()->findByName(account);
340 kmkernel->acctMgr()->singleCheckMail(acct,
false);
343 void KMKernel::loadProfile(
const TQString& )
347 void KMKernel::saveToProfile(
const TQString& )
const
351 void KMKernel::openReader(
bool onlyCheck )
354 KMainWindow *ktmw = 0;
355 kdDebug(5006) <<
"KMKernel::openReader called" << endl;
357 if (KMainWindow::memberList)
358 for (ktmw = KMainWindow::memberList->first(); ktmw;
359 ktmw = KMainWindow::memberList->next())
360 if (ktmw->isA(
"KMMainWin"))
365 mWin = (KMMainWin *) ktmw;
366 activate = !onlyCheck;
370 mWin =
new KMMainWin;
378 #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY
379 KStartupInfo::setNewStartupId( mWin, kapp->startupId() );
385 const TQString &bcc,
const TQString &subject,
386 const TQString &body,
int hidden,
387 const KURL &messageFile,
388 const KURL::List &attachURLs,
389 const QCStringList &customHeaders)
391 kdDebug(5006) <<
"KMKernel::openComposer called" << endl;
398 msg->setTo( KMMsgBase::decodeRFC2047String( to.latin1() ) );
400 msg->setCc( KMMsgBase::decodeRFC2047String( cc.latin1() ) );
402 msg->setBcc( KMMsgBase::decodeRFC2047String( bcc.latin1() ) );
403 if (!subject.isEmpty()) msg->setSubject(subject);
404 if (!messageFile.isEmpty() && messageFile.isLocalFile()) {
405 TQCString str = KPIM::kFileToString( messageFile.path(),
true, false );
406 if( !str.isEmpty() ) {
407 msg->
setBody( TQString(TQString::fromLocal8Bit( str )).utf8() );
410 parser.process( NULL, NULL );
413 else if (!body.isEmpty())
420 parser.process( NULL, NULL );
423 if (!customHeaders.isEmpty())
425 for ( QCStringList::ConstIterator it = customHeaders.begin() ; it != customHeaders.end() ; ++it )
426 if ( !(*it).isEmpty() )
428 const int pos = (*it).find(
':' );
431 TQCString header, value;
432 header = (*it).left( pos ).stripWhiteSpace();
433 value = (*it).mid( pos+1 ).stripWhiteSpace();
434 if ( !header.isEmpty() && !value.isEmpty() )
440 KMail::Composer * cWin = KMail::makeComposer( msg );
441 cWin->setCharset(
"",
true);
442 for ( KURL::List::ConstIterator it = attachURLs.begin() ; it != attachURLs.end() ; ++it )
443 cWin->addAttach((*it));
448 #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY
449 KStartupInfo::setNewStartupId( cWin, kapp->startupId() );
457 const TQString &bcc,
const TQString &subject,
458 const TQString &body,
int hidden,
459 const TQString &attachName,
460 const TQCString &attachCte,
461 const TQCString &attachData,
462 const TQCString &attachType,
463 const TQCString &attachSubType,
464 const TQCString &attachParamAttr,
465 const TQString &attachParamValue,
466 const TQCString &attachContDisp )
468 kdDebug(5006) <<
"KMKernel::openComposer called (deprecated version)" << endl;
470 return openComposer ( to, cc, bcc, subject, body, hidden,
471 attachName, attachCte, attachData,
472 attachType, attachSubType, attachParamAttr,
473 attachParamValue, attachContDisp, TQCString() );
477 const TQString &bcc,
const TQString &subject,
478 const TQString &body,
int hidden,
479 const TQString &attachName,
480 const TQCString &attachCte,
481 const TQCString &attachData,
482 const TQCString &attachType,
483 const TQCString &attachSubType,
484 const TQCString &attachParamAttr,
485 const TQString &attachParamValue,
486 const TQCString &attachContDisp,
487 const TQCString &attachCharset )
489 kdDebug(5006) <<
"KMKernel::openComposer called (deprecated version)" << endl;
490 return openComposer ( to, cc, bcc, subject, body, hidden,
491 attachName, attachCte, attachData,
492 attachType, attachSubType, attachParamAttr,
493 attachParamValue, attachContDisp, attachCharset, 0 );
497 const TQString &bcc,
const TQString &subject,
498 const TQString &body,
int hidden,
499 const TQString &attachName,
500 const TQCString &attachCte,
501 const TQCString &attachData,
502 const TQCString &attachType,
503 const TQCString &attachSubType,
504 const TQCString &attachParamAttr,
505 const TQString &attachParamValue,
506 const TQCString &attachContDisp,
507 const TQCString &attachCharset,
508 unsigned int identity )
510 kdDebug(5006) <<
"KMKernel::openComposer()" << endl;
513 KMMessagePart *msgPart = 0;
516 if ( !cc.isEmpty() ) msg->setCc(cc);
517 if ( !bcc.isEmpty() ) msg->setBcc(bcc);
518 if ( !subject.isEmpty() ) msg->setSubject(subject);
519 if ( !to.isEmpty() ) msg->setTo(to);
520 if ( identity > 0 ) msg->
setHeaderField(
"X-KMail-Identity", TQString::number( identity ) );
521 if ( !body.isEmpty() ) {
525 parser.process( NULL, NULL );
528 bool iCalAutoSend =
false;
529 bool noWordWrap =
false;
530 bool isICalInvitation =
false;
531 KConfigGroup options( config(),
"Groupware" );
532 if ( !attachData.isEmpty() ) {
533 isICalInvitation = attachName ==
"cal.ics" &&
534 attachType ==
"text" &&
535 attachSubType ==
"calendar" &&
536 attachParamAttr ==
"method";
538 if ( isICalInvitation && bcc.isEmpty() )
540 if ( isICalInvitation &&
541 GlobalSettings::self()->legacyBodyInvites() ) {
545 TQString(
"text/calendar; method=%1; "
546 "charset=\"utf-8\"" ).
547 arg( attachParamValue ) );
553 msgPart =
new KMMessagePart;
554 msgPart->setName( attachName );
555 msgPart->setCteStr( attachCte );
556 msgPart->setBodyEncoded( attachData );
557 msgPart->setTypeStr( attachType );
558 msgPart->setSubtypeStr( attachSubType );
559 msgPart->setParameter( attachParamAttr, attachParamValue );
560 if( ! GlobalSettings::self()->exchangeCompatibleInvitations() ) {
561 msgPart->setContentDisposition( attachContDisp );
563 if( !attachCharset.isEmpty() ) {
566 msgPart->setCharset( attachCharset );
569 KConfigGroup options( config(),
"Groupware" );
570 iCalAutoSend = options.readBoolEntry(
"AutomaticSending",
true );
574 KMail::Composer * cWin = KMail::makeComposer();
575 cWin->setMsg( msg, !isICalInvitation );
576 cWin->setSigningAndEncryptionDisabled( isICalInvitation
577 && GlobalSettings::self()->legacyBodyInvites() );
578 cWin->setAutoDelete(
true );
580 cWin->disableWordWrap();
582 cWin->setCharset(
"",
true );
584 cWin->addAttach(msgPart);
586 if ( isICalInvitation ) {
587 cWin->disableRecipientNumberCheck();
588 cWin->disableForgottenAttachmentsCheck();
591 if ( hidden == 0 && !iCalAutoSend ) {
595 #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY
596 KStartupInfo::setNewStartupId( cWin, kapp->startupId() );
599 cWin->setAutoDeleteWindow(
true );
609 TQStringList::const_iterator it = availTransports.find( transport );
610 if ( it == availTransports.end() ) {
611 kdWarning() <<
"The transport you entered is not available" << endl;
618 const TQString &bcc,
const TQString &subject,
619 const TQString &body,
bool hidden)
624 if (!cc.isEmpty()) msg->setCc(cc);
625 if (!bcc.isEmpty()) msg->setBcc(bcc);
626 if (!subject.isEmpty()) msg->setSubject(subject);
627 if (!to.isEmpty()) msg->setTo(to);
628 if (!body.isEmpty()) {
632 parser.process( NULL, NULL );
635 KMail::Composer * cWin = KMail::makeComposer( msg );
636 cWin->setCharset(
"",
true);
641 #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY
642 KStartupInfo::setNewStartupId( cWin, kapp->startupId() );
646 return DCOPRef( cWin->asMailComposerIFace() );
655 const KURL &attachURL)
657 KMail::Composer * win = 0;
664 folder = currentFolder();
665 id = folder ? folder->identity() : 0;
672 if (!to.isEmpty()) msg->setTo(to);
673 if (!cc.isEmpty()) msg->setCc(cc);
674 if (!bcc.isEmpty()) msg->setBcc(bcc);
678 parser.process( NULL, folder );
679 win = makeComposer( msg,
id );
682 parser.process( NULL, folder );
683 win = makeComposer( msg );
687 if(!attachURL.isEmpty() && attachURL.isValid()) {
688 win->addAttach(attachURL);
695 return DCOPRef( win->asMailComposerIFace() );
698 int KMKernel::viewMessage(
const KURL & messageFile )
700 KMOpenMsgCommand *openCommand =
new KMOpenMsgCommand( 0, messageFile );
702 openCommand->start();
712 msg->setSubject( i18n(
"Certificate Signature Request" ) );
713 if (!to.isEmpty()) msg->setTo(to);
715 msg->
setBody( i18n(
"Please create a certificate from attachment and return to sender." ).utf8() );
717 KMail::Composer * cWin = KMail::makeComposer( msg );
718 cWin->setCharset(
"",
true);
719 cWin->slotSetAlwaysSend(
true );
720 if (!certData.isEmpty()) {
721 KMMessagePart *msgPart =
new KMMessagePart;
722 msgPart->setName(
"smime.p10");
723 msgPart->setCteStr(
"base64");
724 msgPart->setBodyEncodedBinary(certData);
725 msgPart->setTypeStr(
"application");
726 msgPart->setSubtypeStr(
"pkcs10");
727 msgPart->setContentDisposition(
"attachment; filename=smime.p10");
728 cWin->addAttach(msgPart);
735 KMMsgStatus KMKernel::strToStatus(
const TQString &flags)
737 KMMsgStatus status = 0;
738 if (!flags.isEmpty()) {
739 for (uint n = 0; n < flags.length() ; n++) {
742 status |= KMMsgStatusNew;
745 status |= KMMsgStatusUnread;
748 status |= KMMsgStatusOld;
751 status |= KMMsgStatusRead;
754 status |= KMMsgStatusDeleted;
757 status |= KMMsgStatusReplied;
760 status |= KMMsgStatusForwarded;
763 status |= KMMsgStatusQueued;
766 status |= KMMsgStatusTodo;
769 status |= KMMsgStatusSent;
772 status |= KMMsgStatusFlag;
775 status |= KMMsgStatusWatched;
778 status |= KMMsgStatusIgnored;
781 status |= KMMsgStatusSpam;
784 status |= KMMsgStatusHam;
787 status |= KMMsgStatusHasAttach;
790 status |= KMMsgStatusHasNoAttach;
801 const TQString & MsgStatusFlags)
803 return dcopAddMessage(foldername, KURL(msgUrlString), MsgStatusFlags);
807 const TQString & MsgStatusFlags)
809 kdDebug(5006) <<
"KMKernel::dcopAddMessage called" << endl;
811 if ( foldername.isEmpty() || foldername.startsWith(
"."))
815 bool readFolderMsgIds =
false;
816 TQString _foldername = foldername.stripWhiteSpace();
817 _foldername = _foldername.replace(
'\\',
"");
819 if ( foldername != mAddMessageLastFolder ) {
820 mAddMessageMsgIds.clear();
821 readFolderMsgIds =
true;
822 mAddMessageLastFolder = foldername;
825 if (!msgUrl.isEmpty() && msgUrl.isLocalFile()) {
834 const TQCString messageText =
835 KPIM::kFileToString( msgUrl.path(),
true, false );
836 if ( messageText.isEmpty() )
840 msg->fromString( messageText );
842 if (readFolderMsgIds) {
843 if ( foldername.contains(
"/")) {
844 TQString tmp_fname =
"";
849 TQStringList subFList = TQStringList::split(
"/",_foldername,
false);
851 for ( TQStringList::Iterator it = subFList.begin(); it != subFList.end(); ++it ) {
852 TQString _newFolder = *it;
853 if(_newFolder.startsWith(
"."))
return -1;
856 folder = the_folderMgr->findOrCreate(*it,
false);
859 tmp_fname =
"/" + *it;
864 tmp_fname +=
"/" + *it;
865 if(!the_folderMgr->getFolderByURL( tmp_fname )) {
866 folder = the_folderMgr->createFolder(*it,
false, folder->
folderType(), subfolder);
869 if(!(folder = the_folderMgr->getFolderByURL( tmp_fname )))
return -1;
873 mAddMsgCurrentFolder = the_folderMgr->getFolderByURL( tmp_fname );
874 if(!folder)
return -1;
877 mAddMsgCurrentFolder = the_folderMgr->findOrCreate(_foldername,
false);
881 if ( mAddMsgCurrentFolder ) {
882 if (readFolderMsgIds) {
907 mAddMsgCurrentFolder->
open(
"dcopadd");
908 for( i=0; i<mAddMsgCurrentFolder->
count(); i++) {
909 KMMsgBase *mb = mAddMsgCurrentFolder->
getMsgBase(i);
910 TQString
id = mb->msgIdMD5();
911 if (
id.isEmpty() ) {
914 id = mb->fromStrip();
922 if ( !
id.isEmpty() ) {
923 mAddMessageMsgIds.append(
id);
926 mAddMsgCurrentFolder->
close(
"dcopadd");
929 TQString msgId = msg->msgIdMD5();
930 if ( msgId.isEmpty()) {
932 if ( msgId.isEmpty() )
933 msgId = msg->fromStrip();
934 if ( msgId.isEmpty() )
935 msgId = msg->toStrip();
940 int k = mAddMessageMsgIds.findIndex( msgId );
944 if ( !msgId.isEmpty() ) {
945 mAddMessageMsgIds.append( msgId );
948 if ( !MsgStatusFlags.isEmpty() ) {
949 KMMsgStatus status = strToStatus(MsgStatusFlags);
954 if ( mAddMsgCurrentFolder->
addMsg( msg, &index ) == 0 ) {
955 mAddMsgCurrentFolder->
unGetMsg( index );
977 mAddMessageMsgIds.clear();
978 mAddMessageLastFolder = TQString();
982 const TQString & msgUrlString,
983 const TQString & MsgStatusFlags)
990 const TQString & MsgStatusFlags)
994 kdDebug(5006) <<
"KMKernel::dcopAddMessage_fastImport called" << endl;
996 if ( foldername.isEmpty() || foldername.startsWith(
"."))
1000 bool createNewFolder =
false;
1002 TQString _foldername = foldername.stripWhiteSpace();
1003 _foldername = _foldername.replace(
'\\',
"");
1005 if ( foldername != mAddMessageLastFolder ) {
1006 createNewFolder =
true;
1007 mAddMessageLastFolder = foldername;
1011 if ( !msgUrl.isEmpty() && msgUrl.isLocalFile() ) {
1012 const TQCString messageText =
1013 KPIM::kFileToString( msgUrl.path(),
true, false );
1014 if ( messageText.isEmpty() )
1018 msg->fromString( messageText );
1020 if (createNewFolder) {
1021 if ( foldername.contains(
"/")) {
1022 TQString tmp_fname =
"";
1027 TQStringList subFList = TQStringList::split(
"/",_foldername,
false);
1029 for ( TQStringList::Iterator it = subFList.begin(); it != subFList.end(); ++it ) {
1030 TQString _newFolder = *it;
1031 if(_newFolder.startsWith(
"."))
return -1;
1034 folder = the_folderMgr->findOrCreate(*it,
false);
1037 tmp_fname =
"/" + *it;
1042 tmp_fname +=
"/" + *it;
1043 if(!the_folderMgr->getFolderByURL( tmp_fname )) {
1044 folder = the_folderMgr->createFolder(*it,
false, folder->
folderType(), subfolder);
1046 if(!(folder = the_folderMgr->getFolderByURL( tmp_fname )))
return -1;
1050 mAddMsgCurrentFolder = the_folderMgr->getFolderByURL( tmp_fname );
1051 if(!folder)
return -1;
1054 mAddMsgCurrentFolder = the_folderMgr->findOrCreate(_foldername,
false);
1058 if ( mAddMsgCurrentFolder ) {
1061 if( !MsgStatusFlags.isEmpty() ) {
1062 KMMsgStatus status = strToStatus(MsgStatusFlags);
1066 if ( mAddMsgCurrentFolder->
addMsg( msg, &index ) == 0 ) {
1067 mAddMsgCurrentFolder->
unGetMsg( index );
1084 void KMKernel::showImportArchiveDialog()
1087 KMail::ImportArchiveDialog *importDialog =
new KMail::ImportArchiveDialog( mainWidget, WDestructiveClose );
1088 importDialog->setFolder( mainWidget->folderTree()->currentFolder() );
1089 importDialog->show();
1092 TQStringList KMKernel::folderList()
const
1094 TQStringList folders;
1095 const TQString localPrefix =
"/Local";
1096 folders << localPrefix;
1097 the_folderMgr->getFolderURLS( folders, localPrefix );
1098 the_imapFolderMgr->getFolderURLS( folders );
1099 the_dimapFolderMgr->getFolderURLS( folders );
1103 DCOPRef KMKernel::getFolder(
const TQString& vpath )
1105 const TQString localPrefix =
"/Local";
1106 if ( the_folderMgr->getFolderByURL( vpath ) )
1107 return DCOPRef(
new FolderIface( vpath ) );
1108 else if ( vpath.startsWith( localPrefix ) &&
1109 the_folderMgr->getFolderByURL( vpath.mid( localPrefix.length() ) ) )
1110 return DCOPRef(
new FolderIface( vpath.mid( localPrefix.length() ) ) );
1111 else if ( the_imapFolderMgr->getFolderByURL( vpath ) )
1112 return DCOPRef(
new FolderIface( vpath ) );
1113 else if ( the_dimapFolderMgr->getFolderByURL( vpath ) )
1114 return DCOPRef(
new FolderIface( vpath ) );
1118 void KMKernel::raise()
1120 DCOPRef kmail(
"kmail",
"kmail" );
1121 kmail.call(
"newInstance" );
1126 KMMainWidget *mainWidget = 0;
1127 if (KMainWindow::memberList) {
1128 KMainWindow *win = 0;
1132 for (win = KMainWindow::memberList->first(); win;
1133 win = KMainWindow::memberList->next()) {
1135 l = win->queryList(
"KMMainWidget");
1136 if (l && l->first()) {
1137 mainWidget =
dynamic_cast<KMMainWidget *
>(l->first());
1138 if (win->isActiveWindow())
1148 if (!folder || (idx == -1))
1151 KMMsgBase *msgBase = folder->
getMsgBase(idx);
1154 bool unGet = !msgBase->isMessage();
1157 KMReaderMainWin *win =
new KMReaderMainWin(
false,
false );
1159 newMessage->setParent( msg->parent() );
1162 win->showMsg( GlobalSettings::self()->overrideCharacterEncoding(), newMessage );
1178 if (!folder || (idx == -1))
1181 KMMsgBase *msgBase = folder->
getMsgBase(idx);
1184 bool unGet = !msgBase->isMessage();
1186 TQString result = msg->
from();
1192 TQString KMKernel::debugScheduler()
1194 TQString res = KMail::ActionScheduler::debug();
1198 TQString KMKernel::debugSernum( TQ_UINT32 serialNumber )
1201 if (serialNumber != 0) {
1208 if (folder && (idx != -1)) {
1213 res.append( TQString(
" subject %s,\n sender %s,\n date %s.\n" )
1214 .arg( msg->subject() )
1215 .arg( msg->fromStrip() )
1216 .arg( msg->dateStr() ) );
1218 res.append( TQString(
"Invalid serial number." ) );
1221 res.append( TQString(
"Invalid serial number." ) );
1230 mBackgroundTasksTimer->stop();
1231 mJobScheduler->pause();
1236 mJobScheduler->resume();
1237 mBackgroundTasksTimer->start( 4 * 60 * 60 * 1000,
true );
1242 if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Offline )
1245 GlobalSettings::setNetworkState( GlobalSettings::EnumNetworkState::Offline );
1246 BroadcastStatus::instance()->setStatusMsg( i18n(
"KMail is set to be offline; all network jobs are suspended"));
1247 emit onlineStatusChanged( (GlobalSettings::EnumNetworkState::type)GlobalSettings::networkState() );
1252 if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Online )
1255 GlobalSettings::setNetworkState( GlobalSettings::EnumNetworkState::Online );
1256 BroadcastStatus::instance()->setStatusMsg( i18n(
"KMail is set to be online; all network jobs resumed"));
1257 emit onlineStatusChanged( (GlobalSettings::EnumNetworkState::type)GlobalSettings::networkState() );
1259 if ( kmkernel->msgSender()->sendImmediate() ) {
1260 kmkernel->msgSender()->sendQueued();
1266 if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Offline )
1275 if ( s_askingToGoOnline ) {
1279 if ( kmkernel->isOffline() ) {
1280 s_askingToGoOnline =
true;
1283 i18n(
"KMail is currently in offline mode. "
1284 "How do you want to proceed?"),
1285 i18n(
"Online/Offline"),
1286 i18n(
"Work Online"),
1287 i18n(
"Work Offline"));
1289 s_askingToGoOnline =
false;
1290 if( rc == KMessageBox::No ) {
1293 kmkernel->resumeNetworkJobs();
1303 void KMKernel::quit()
1354 void KMKernel::testDir(
const char *_name)
1356 TQString foldersPath = TQDir::homeDirPath() + TQString( _name );
1357 TQFileInfo info( foldersPath );
1358 if ( !info.exists() ) {
1359 if ( ::mkdir( TQFile::encodeName( foldersPath ) , S_IRWXU ) == -1 ) {
1360 KMessageBox::sorry(0, i18n(
"KMail could not create folder '%1';\n"
1361 "please make sure that you can view and "
1362 "modify the content of the folder '%2'.")
1363 .arg( foldersPath ).arg( TQDir::homeDirPath() ) );
1367 if ( !info.isDir() || !info.isReadable() || !info.isWritable() ) {
1368 KMessageBox::sorry(0, i18n(
"The permissions of the folder '%1' are "
1370 "please make sure that you can view and modify "
1371 "the content of this folder.")
1372 .arg( foldersPath ) );
1380 void KMKernel::recoverDeadLetters()
1383 if ( !dir.exists() ) {
1384 kdWarning(5006) <<
"Autosave directory " << dir.path() <<
" not found!" << endl;
1388 const TQStringList entryList = dir.entryList( TQDir::Files | TQDir::NoSymLinks, TQDir::Unsorted );
1389 for (
unsigned int i = 0; i < entryList.size(); i++ ) {
1390 const TQString fileName = entryList[i];
1391 TQFile file( dir.path() +
'/' + fileName );
1392 if ( !file.open( IO_ReadOnly ) ) {
1393 kdWarning(5006) <<
"Unable to open autosave file " << fileName << endl;
1396 const TQByteArray msgData = file.readAll();
1399 if ( msgData.isEmpty() ) {
1400 kdWarning(5006) <<
"autosave file " << fileName <<
" is empty!" << endl;
1405 msg->fromByteArray( msgData );
1406 KMail::Composer * win = KMail::makeComposer();
1407 win->setMsg( msg,
false,
false,
true );
1408 win->setAutoSaveFilename( fileName );
1414 void KMKernel::initFolders(KConfig* cfg)
1418 name = cfg->readEntry(
"inboxFolder");
1424 if (name.isEmpty()) name = I18N_NOOP(
"inbox");
1426 the_inboxFolder = (
KMFolder*)the_folderMgr->findOrCreate(name);
1428 if (the_inboxFolder->
canAccess() != 0) {
1429 emergencyExit( i18n(
"You do not have read/write permission to your inbox folder.") );
1432 the_inboxFolder->setSystemFolder(
true);
1434 the_inboxFolder->setUserWhoField( TQString() );
1437 the_outboxFolder = the_folderMgr->findOrCreate(cfg->readEntry(
"outboxFolder", I18N_NOOP(
"outbox")));
1438 if (the_outboxFolder->
canAccess() != 0) {
1439 emergencyExit( i18n(
"You do not have read/write permission to your outbox folder.") );
1443 the_outboxFolder->setSystemFolder(
true);
1445 the_outboxFolder->setUserWhoField( TQString() );
1454 the_outboxFolder->
open(
"kmkernel");
1456 the_sentFolder = the_folderMgr->findOrCreate(cfg->readEntry(
"sentFolder", I18N_NOOP(
"sent-mail")));
1458 emergencyExit( i18n(
"You do not have read/write permission to your sent-mail folder.") );
1460 the_sentFolder->setSystemFolder(
true);
1462 the_sentFolder->setUserWhoField( TQString() );
1465 the_trashFolder = the_folderMgr->findOrCreate(cfg->readEntry(
"trashFolder", I18N_NOOP(
"trash")));
1466 if (the_trashFolder->
canAccess() != 0) {
1467 emergencyExit( i18n(
"You do not have read/write permission to your trash folder.") );
1469 the_trashFolder->setSystemFolder(
true );
1471 the_trashFolder->setUserWhoField( TQString() );
1474 the_draftsFolder = the_folderMgr->findOrCreate(cfg->readEntry(
"draftsFolder", I18N_NOOP(
"drafts")));
1475 if (the_draftsFolder->
canAccess() != 0) {
1476 emergencyExit( i18n(
"You do not have read/write permission to your drafts folder.") );
1478 the_draftsFolder->setSystemFolder(
true );
1480 the_draftsFolder->setUserWhoField( TQString() );
1481 the_draftsFolder->
open(
"kmkernel");
1483 the_templatesFolder =
1484 the_folderMgr->findOrCreate( cfg->readEntry(
"templatesFolder",
1485 I18N_NOOP(
"templates") ) );
1486 if ( the_templatesFolder->
canAccess() != 0 ) {
1487 emergencyExit( i18n(
"You do not have read/write permission to your templates folder.") );
1489 the_templatesFolder->setSystemFolder(
true );
1491 the_templatesFolder->setUserWhoField( TQString() );
1492 the_templatesFolder->
open(
"kmkernel");
1496 void KMKernel::init()
1498 the_shuttingDown =
false;
1499 the_server_is_ready =
false;
1501 KConfig* cfg = KMKernel::config();
1505 KConfigGroupSaver saver(cfg,
"General");
1506 the_firstStart = cfg->readBoolEntry(
"first-start",
true);
1507 cfg->writeEntry(
"first-start",
false);
1508 the_previousVersion = cfg->readEntry(
"previous-version");
1509 cfg->writeEntry(
"previous-version", KMAIL_VERSION);
1510 TQString foldersPath = cfg->readPathEntry(
"folders" );
1511 kdDebug(5006) << k_funcinfo <<
"foldersPath (from config): '" << foldersPath <<
"'" << endl;
1513 if ( foldersPath.isEmpty() ) {
1516 cfg->writePathEntry(
"folders", foldersPath );
1518 kdDebug(5006) << k_funcinfo <<
"foldersPath (after transferMail): '" << foldersPath <<
"'" << endl;
1524 the_undoStack =
new UndoStack(20);
1525 the_folderMgr =
new KMFolderMgr(foldersPath);
1526 the_imapFolderMgr =
new KMFolderMgr( KMFolderImap::cacheLocation(), KMImapDir);
1527 the_dimapFolderMgr =
new KMFolderMgr( KMFolderCachedImap::cacheLocation(), KMDImapDir);
1528 recreateCorruptIndexFiles();
1530 the_searchFolderMgr =
new KMFolderMgr(locateLocal(
"data",
"kmail/search"), KMSearchDir);
1531 KMFolder *lsf = the_searchFolderMgr->find( i18n(
"Last Search") );
1533 the_searchFolderMgr->remove( lsf );
1536 the_filterMgr =
new KMFilterMgr();
1537 the_popFilterMgr =
new KMFilterMgr(
true);
1542 the_filterMgr->readConfig();
1543 the_popFilterMgr->readConfig();
1544 cleanupImapFolders();
1546 the_msgSender =
new KMSender;
1547 the_server_is_ready =
true;
1550 KConfigGroupSaver saver(cfg,
"Composer");
1551 if (cfg->readListEntry(
"pref-charsets").isEmpty())
1553 cfg->writeEntry(
"pref-charsets",
"us-ascii,iso-8859-1,locale,utf-8");
1557 mICalIface->readConfig();
1559 #ifdef HAVE_INDEXLIB
1560 the_msgIndex =
new KMMsgIndex(
this);
1566 the_weaver =
new KPIM::ThreadWeaver::Weaver(
this );
1567 the_weaverLogger =
new KPIM::ThreadWeaver::WeaverThreadLogger(
this);
1568 the_weaverLogger->attach (the_weaver);
1571 connect( the_folderMgr, TQT_SIGNAL( folderRemoved(
KMFolder*) ),
1572 this, TQT_SIGNAL( folderRemoved(
KMFolder*) ) );
1573 connect( the_dimapFolderMgr, TQT_SIGNAL( folderRemoved(
KMFolder*) ),
1574 this, TQT_SIGNAL( folderRemoved(
KMFolder*) ) );
1575 connect( the_imapFolderMgr, TQT_SIGNAL( folderRemoved(
KMFolder*) ),
1576 this, TQT_SIGNAL( folderRemoved(
KMFolder*) ) );
1577 connect( the_searchFolderMgr, TQT_SIGNAL( folderRemoved(
KMFolder*) ),
1578 this, TQT_SIGNAL( folderRemoved(
KMFolder*) ) );
1580 mBackgroundTasksTimer =
new TQTimer(
this,
"mBackgroundTasksTimer" );
1581 connect( mBackgroundTasksTimer, TQT_SIGNAL( timeout() ),
this, TQT_SLOT( slotRunBackgroundTasks() ) );
1582 #ifdef DEBUG_SCHEDULER // for debugging, see jobscheduler.h
1583 mBackgroundTasksTimer->start( 10000,
true );
1585 mBackgroundTasksTimer->start( 5 * 60000,
true );
1589 for (
int i = 0; ( codec = TQTextCodec::codecForIndex ( i ) ); i++ ) {
1590 const TQString asciiString(
"azAZ19,.-#+!?=()&" );
1591 const TQCString encodedString = codec->fromUnicode( asciiString );
1592 if ( TQString::fromAscii( encodedString ) != asciiString ) {
1593 mNonAsciiCompatibleCodecs.append( codec );
1598 bool KMKernel::isCodecAsciiCompatible(
const TQTextCodec *codec )
1600 return !mNonAsciiCompatibleCodecs.contains( codec );
1603 void KMKernel::readConfig()
1610 void KMKernel::cleanupImapFolders()
1612 KMAccount *acct = 0;
1613 KMFolderNode *node = the_imapFolderMgr->dir().first();
1616 if (node->isDir() || ((acct = the_acctMgr->
find(node->id()))
1617 && ( acct->type() ==
"imap" )) )
1619 node = the_imapFolderMgr->dir().next();
1623 static_cast<KMFolderImap*
>( folder->storage() )->setAlreadyRemoved(
true );
1624 the_imapFolderMgr->remove(folder);
1625 node = the_imapFolderMgr->dir().first();
1629 node = the_dimapFolderMgr->dir().first();
1632 if (node->isDir() || ((acct = the_acctMgr->
find(node->id()))
1633 && ( acct->type() ==
"cachedimap" )) )
1635 node = the_dimapFolderMgr->dir().next();
1637 the_dimapFolderMgr->remove(static_cast<KMFolder*>(node));
1638 node = the_dimapFolderMgr->dir().first();
1642 the_imapFolderMgr->quiet(
true);
1643 for (acct = the_acctMgr->
first(); acct; acct = the_acctMgr->
next())
1646 KMAcctImap *imapAcct;
1648 if (acct->type() !=
"imap")
continue;
1649 fld =
static_cast<KMFolderImap*
>(the_imapFolderMgr
1650 ->findOrCreate(TQString::number(acct->id()),
false, acct->id())->storage());
1651 fld->setNoContent(
true);
1652 fld->folder()->setLabel(acct->name());
1653 imapAcct =
static_cast<KMAcctImap*
>(acct);
1654 fld->setAccount(imapAcct);
1655 imapAcct->setImapFolder(fld);
1656 fld->close(
"kernel",
true );
1658 the_imapFolderMgr->quiet(
false);
1660 the_dimapFolderMgr->quiet(
true );
1661 for (acct = the_acctMgr->
first(); acct; acct = the_acctMgr->
next())
1663 KMFolderCachedImap *cfld = 0;
1664 KMAcctCachedImap *cachedImapAcct;
1666 if (acct->type() !=
"cachedimap" )
continue;
1668 KMFolder* fld = the_dimapFolderMgr->find(TQString::number(acct->id()));
1670 cfld =
static_cast<KMFolderCachedImap*
>( fld->storage() );
1673 cfld =
static_cast<KMFolderCachedImap*
>(the_dimapFolderMgr->createFolder(TQString::number(acct->id()),
1674 false, KMFolderTypeCachedImap)->storage());
1676 KMessageBox::error(0,(i18n(
"Cannot create file `%1' in %2.\nKMail cannot start without it.").arg(acct->name()).arg(the_dimapFolderMgr->basePath())));
1679 cfld->folder()->setId( acct->id() );
1682 cfld->setNoContent(
true);
1683 cfld->folder()->setLabel(acct->name());
1684 cachedImapAcct =
static_cast<KMAcctCachedImap*
>(acct);
1685 cfld->setAccount(cachedImapAcct);
1686 cachedImapAcct->setImapFolder(cfld);
1687 cfld->close(
"kmkernel");
1689 the_dimapFolderMgr->quiet(
false );
1692 void KMKernel::recreateCorruptIndexFiles()
1694 TQValueList<TQGuardedPtr<KMFolder> > folders;
1695 TQValueList<KMFolderIndex*> foldersWithBrokenIndex;
1696 TQStringList strList;
1697 the_folderMgr->createFolderList( &strList, &folders );
1698 the_imapFolderMgr->createFolderList( &strList, &folders );
1699 the_dimapFolderMgr->createFolderList( &strList, &folders );
1700 for (
int i = 0; folders.at(i) != folders.end(); i++ ) {
1701 KMFolder *
const folder = *folders.at(i);
1702 if ( !folder || folder->isDir() || folder->
isOpened() )
1705 if ( index && index->
indexStatus() != KMFolderIndex::IndexOk ) {
1706 foldersWithBrokenIndex.append( index );
1710 if ( !foldersWithBrokenIndex.isEmpty() ) {
1711 TQStringList folderNames;
1712 for ( uint i = 0; i < foldersWithBrokenIndex.size(); i++ ) {
1713 folderNames << foldersWithBrokenIndex[i]->
label();
1716 KMessageBox::informationList( 0, i18n(
"There is a problem with the mail index of the following "
1717 "folders, the indices will now be regenerated.\n"
1718 "This can happen because the index files are out of date, missing or corrupted.\n"
1719 "Contact your administrator if this happens frequently.\n"
1720 "Some information, like status flags, might get lost." ),
1721 folderNames, i18n(
"Problem with mail indices" ) );
1723 for ( uint i = 0; i < foldersWithBrokenIndex.size(); i++ ) {
1724 foldersWithBrokenIndex[i]->silentlyRecreateIndex();
1729 bool KMKernel::doSessionManagement()
1733 if (kapp->isRestored()){
1735 while (KMMainWin::canBeRestored(n)){
1737 if (KMMainWin::classNameOfToplevel(n) ==
"KMMainWin")
1738 (
new KMMainWin)->restore(n);
1746 void KMKernel::closeAllKMailWindows()
1748 if (!KMainWindow::memberList)
return;
1749 TQPtrListIterator<KMainWindow> it(*KMainWindow::memberList);
1750 KMainWindow *window = 0;
1751 while ((window = it.current()) != 0) {
1753 if (window->isA(
"KMMainWindow") ||
1754 window->inherits(
"KMail::SecondaryWindow"))
1755 window->close(
true );
1759 void KMKernel::cleanup(
void)
1762 the_shuttingDown =
true;
1763 closeAllKMailWindows();
1767 delete the_filterMgr;
1769 delete the_msgSender;
1771 delete the_filterActionDict;
1772 the_filterActionDict = 0;
1773 delete the_undoStack;
1775 delete the_popFilterMgr;
1776 the_popFilterMgr = 0;
1783 KConfig* config = KMKernel::config();
1784 KConfigGroupSaver saver(config,
"General");
1786 if (the_trashFolder) {
1788 the_trashFolder->
close(
"kmkernel",
true);
1790 if (config->readBoolEntry(
"empty-trash-on-exit",
true))
1792 if ( the_trashFolder->
count(
true ) > 0 )
1799 TQValueList<TQGuardedPtr<KMFolder> > folders;
1800 TQStringList strList;
1802 the_folderMgr->createFolderList(&strList, &folders);
1803 for (
int i = 0; folders.at(i) != folders.end(); i++)
1805 folder = *folders.at(i);
1806 if (!folder || folder->isDir())
continue;
1807 folder->
close(
"kmkernel",
true);
1811 the_searchFolderMgr->createFolderList(&strList, &folders);
1812 for (
int i = 0; folders.at(i) != folders.end(); i++)
1814 folder = *folders.at(i);
1815 if (!folder || folder->isDir())
continue;
1816 folder->
close(
"kmkernel",
true);
1819 delete the_msgIndex;
1821 delete the_folderMgr;
1823 delete the_imapFolderMgr;
1824 the_imapFolderMgr = 0;
1825 delete the_dimapFolderMgr;
1826 the_dimapFolderMgr = 0;
1827 delete the_searchFolderMgr;
1828 the_searchFolderMgr = 0;
1829 delete mConfigureDialog;
1830 mConfigureDialog = 0;
1835 if ( RecentAddresses::exists() )
1845 TQFileInfo fi( TQDir::home(),
"KMail" );
1846 if ( fi.exists() && fi.isDir() ) {
1847 dir = TQDir::homeDirPath() +
"/KMail";
1849 destinationDir = dir;
1853 if ( dir.isEmpty() ) {
1855 fi.setFile( TQDir::home(),
"Mail" );
1856 if ( fi.exists() && fi.isDir() &&
1857 TQFile::exists( TQDir::homeDirPath() +
"/Mail/.inbox.index" ) ) {
1860 dir = TQDir::homeDirPath() +
"/Mail";
1862 destinationDir = dir;
1867 if ( dir.isEmpty() ) {
1873 const TQString kmailName = kapp->aboutData()->programName();
1875 if ( KIO::NetAccess::exists( destinationDir,
true, 0 ) ) {
1878 msg = i18n(
"%1-%3 is the application name, %4-%7 are folder path",
1879 "<qt>The <i>%4</i> folder exists. "
1880 "%1 now uses the <i>%5</i> folder for "
1882 "%2 can move the contents of <i>%6<i> into this folder for "
1883 "you, though this may replace any existing files with "
1884 "the same name in <i>%7</i>.<p>"
1885 "<strong>Would you like %3 to move the mail "
1886 "files now?</strong></qt>" )
1887 .arg( kmailName, kmailName, kmailName )
1888 .arg( dir, destinationDir, dir, destinationDir );
1890 msg = i18n(
"%1-%3 is the application name, %4-%6 are folder path",
1891 "<qt>The <i>%4</i> folder exists. "
1892 "%1 now uses the <i>%5</i> folder for "
1893 "its messages. %2 can move the contents of <i>%6</i> into "
1894 "this folder for you.<p>"
1895 "<strong>Would you like %3 to move the mail "
1896 "files now?</strong></qt>" )
1897 .arg( kmailName, kmailName, kmailName )
1898 .arg( dir, destinationDir, dir );
1900 TQString title = i18n(
"Migrate Mail Files?" );
1901 TQString buttonText = i18n(
"Move" );
1903 if ( KMessageBox::questionYesNo( 0, msg, title, buttonText, i18n(
"Do Not Move") ) ==
1905 destinationDir = dir;
1909 if ( !KIO::NetAccess::move( dir, destinationDir ) ) {
1910 kdDebug(5006) << k_funcinfo <<
"Moving " << dir <<
" to " << destinationDir <<
" failed: " << KIO::NetAccess::lastErrorString() << endl;
1911 kdDebug(5006) << k_funcinfo <<
"Deleting " << destinationDir << endl;
1912 KIO::NetAccess::del( destinationDir, 0 );
1913 destinationDir = dir;
1922 void KMKernel::ungrabPtrKb(
void)
1924 if(!KMainWindow::memberList)
return;
1925 TQWidget* widg = KMainWindow::memberList->first();
1929 dpy = widg->x11Display();
1930 XUngrabKeyboard(dpy, CurrentTime);
1931 XUngrabPointer(dpy, CurrentTime);
1936 void KMKernel::kmailMsgHandler(TQtMsgType aType,
const char* aMsg)
1938 static int recurse=-1;
1946 kdDebug(5006) << aMsg << endl;
1951 kdDebug(5006) << kapp->caption() <<
" fatal error "
1953 KMessageBox::error(0, aMsg);
1963 if ( shuttingDown() )
1967 if ( !KMainWindow::memberList )
1970 for ( TQPtrListIterator<KMainWindow> it(*KMainWindow::memberList) ; it.current() != 0; ++it ) {
1971 if ( KMail::Composer * win = ::tqqt_cast<KMail::Composer*>( it.current() ) ) {
1972 win->autoSaveMessage();
1977 while ( win->isComposing() )
1978 tqApp->processEvents();
1985 void KMKernel::action(
bool mailto,
bool check,
const TQString &to,
1986 const TQString &cc,
const TQString &bcc,
1987 const TQString &subj,
const TQString &body,
1988 const KURL &messageFile,
1989 const KURL::List &attachURLs,
1990 const QCStringList &customHeaders)
1993 openComposer( to, cc, bcc, subj, body, 0, messageFile, attachURLs, customHeaders );
1995 openReader( check );
2002 void KMKernel::byteArrayToRemoteFile(
const TQByteArray &aData,
const KURL &aURL,
2006 KIO::Job *job = KIO::put(aURL, -1, overwrite,
false);
2007 putData pd; pd.url = aURL; pd.data = aData; pd.offset = 0;
2008 mPutJobs.insert(job, pd);
2009 connect(job, TQT_SIGNAL(dataReq(KIO::Job*,TQByteArray&)),
2010 TQT_SLOT(slotDataReq(KIO::Job*,TQByteArray&)));
2011 connect(job, TQT_SIGNAL(result(KIO::Job*)),
2012 TQT_SLOT(slotResult(KIO::Job*)));
2015 void KMKernel::slotDataReq(KIO::Job *job, TQByteArray &data)
2018 const int MAX_CHUNK_SIZE = 64*1024;
2019 TQMap<KIO::Job*, putData>::Iterator it = mPutJobs.find(job);
2020 assert(it != mPutJobs.end());
2021 int remainingBytes = (*it).data.size() - (*it).offset;
2022 if( remainingBytes > MAX_CHUNK_SIZE )
2025 data.duplicate( (*it).data.data() + (*it).offset, MAX_CHUNK_SIZE );
2026 (*it).offset += MAX_CHUNK_SIZE;
2033 data.duplicate( (*it).data.data() + (*it).offset, remainingBytes );
2034 (*it).data = TQByteArray();
2040 void KMKernel::slotResult(KIO::Job *job)
2042 TQMap<KIO::Job*, putData>::Iterator it = mPutJobs.find(job);
2043 assert(it != mPutJobs.end());
2046 if (job->error() == KIO::ERR_FILE_ALREADY_EXIST)
2048 if (KMessageBox::warningContinueCancel(0,
2049 i18n(
"File %1 exists.\nDo you want to replace it?")
2050 .arg((*it).url.prettyURL()), i18n(
"Save to File"), i18n(
"&Replace"))
2051 == KMessageBox::Continue)
2052 byteArrayToRemoteFile((*it).data, (*it).url,
true);
2054 else job->showErrorDialog();
2056 mPutJobs.remove(it);
2061 KMKernel::config()->sync();
2064 void KMKernel::slotShowConfigurationDialog()
2066 if( !mConfigureDialog ) {
2067 mConfigureDialog =
new ConfigureDialog( 0,
"configure",
false );
2068 connect( mConfigureDialog, TQT_SIGNAL( configChanged() ),
2069 this, TQT_SLOT( slotConfigChanged() ) );
2077 KMMainWin * win =
new KMMainWin;
2080 if( mConfigureDialog->isHidden() )
2083 mConfigureDialog->show();
2086 mConfigureDialog->raise();
2089 void KMKernel::slotConfigChanged()
2092 emit configChanged();
2099 return locateLocal(
"data",
"kmail/" );
2106 return !systemTrayApplets.isEmpty();
2109 bool KMKernel::registerSystemTrayApplet(
const KSystemTray* applet )
2111 if ( systemTrayApplets.findIndex( applet ) == -1 ) {
2112 systemTrayApplets.append( applet );
2119 bool KMKernel::unregisterSystemTrayApplet(
const KSystemTray* applet )
2121 TQValueList<const KSystemTray*>::iterator it =
2122 systemTrayApplets.find( applet );
2123 if ( it != systemTrayApplets.end() ) {
2124 systemTrayApplets.remove( it );
2131 void KMKernel::emergencyExit(
const TQString& reason )
2134 if ( reason.length() == 0 ) {
2135 mesg = i18n(
"KMail encountered a fatal error and will terminate now");
2137 mesg = i18n(
"KMail encountered a fatal error and will "
2138 "terminate now.\nThe error was:\n%1").arg( reason );
2141 kdWarning() << mesg << endl;
2142 KNotifyClient::userEvent( 0,
"<qt>"+mesg+
"</qt>", KNotifyClient::Messagebox, KNotifyClient::Error );
2153 if ( folder == the_outboxFolder )
2155 return folderIsDrafts( folder );
2158 bool KMKernel::folderIsDrafts(
const KMFolder * folder)
2161 if ( folder == the_draftsFolder )
2164 TQString idString = folder->
idString();
2165 if ( idString.isEmpty() )
2170 for ( KPIM::IdentityManager::ConstIterator it=im->begin(); it != im->end(); ++it )
2171 if ( (*it).drafts() == idString )
2176 bool KMKernel::folderIsTemplates(
const KMFolder *folder )
2179 if ( folder == the_templatesFolder )
2182 TQString idString = folder->
idString();
2183 if ( idString.isEmpty() )
2188 for ( KPIM::IdentityManager::ConstIterator it=im->begin(); it != im->end(); ++it )
2189 if ( (*it).templates() == idString )
2194 bool KMKernel::folderIsTrash(
KMFolder * folder)
2197 if (folder == the_trashFolder)
return true;
2198 TQStringList actList = acctMgr()->getAccounts();
2199 TQStringList::Iterator it( actList.begin() );
2200 for( ; it != actList.end() ; ++it ) {
2201 KMAccount* act = acctMgr()->
findByName( *it );
2202 if ( act && ( act->trash() == folder->
idString() ) )
2211 if ( folder == the_sentFolder )
2214 TQString idString = folder->
idString();
2215 if ( idString.isEmpty() )
return false;
2219 for( KPIM::IdentityManager::ConstIterator it = im->begin(); it != im->end(); ++it )
2220 if ( (*it).fcc() == idString )
return true;
2225 if ( !mIdentityManager ) {
2226 kdDebug(5006) <<
"instantating KPIM::IdentityManager" << endl;
2227 mIdentityManager =
new KPIM::IdentityManager(
false,
this,
"mIdentityManager" );
2229 return mIdentityManager;
2232 KMMsgIndex *KMKernel::msgIndex()
2234 return the_msgIndex;
2239 if (KMainWindow::memberList) {
2240 KMainWindow *kmWin = 0;
2243 for (kmWin = KMainWindow::memberList->first(); kmWin;
2244 kmWin = KMainWindow::memberList->next())
2245 if (kmWin->isA(
"KMMainWin"))
2251 kmWin = KMainWindow::memberList->first();
2260 mWin =
new KMMainWin;
2270 TQString title = i18n(
"Empty Trash");
2271 TQString text = i18n(
"Are you sure you want to empty the trash folders of all accounts?");
2272 if (KMessageBox::warningContinueCancel(0, text, title,
2273 KStdGuiItem::cont(),
"confirm_empty_trash")
2274 != KMessageBox::Continue)
2279 for (KMAccount* acct = acctMgr()->first(); acct; acct = acctMgr()->
next())
2289 KConfig* KMKernel::config()
2292 if (!mySelf->mConfig)
2294 mySelf->mConfig = KSharedConfig::openConfig(
"kmailrc" );
2296 KMail::checkConfigUpdates();
2298 return mySelf->mConfig;
2303 assert( mICalIface );
2307 void KMKernel::selectFolder( TQString folderPath )
2309 kdDebug(5006)<<
"Selecting a folder "<<folderPath<<endl;
2310 const TQString localPrefix =
"/Local";
2311 KMFolder *folder = kmkernel->folderMgr()->getFolderByURL( folderPath );
2312 if ( !folder && folderPath.startsWith( localPrefix ) )
2313 folder = the_folderMgr->getFolderByURL( folderPath.mid( localPrefix.length() ) );
2315 folder = kmkernel->imapFolderMgr()->getFolderByURL( folderPath );
2317 folder = kmkernel->dimapFolderMgr()->getFolderByURL( folderPath );
2325 KMFolderTree *tree = widget->folderTree();
2326 tree->doFolderSelected( tree->indexOfFolder( folder ) );
2327 tree->ensureItemVisible( tree->indexOfFolder( folder ) );
2333 TQWidgetList *l = kapp->topLevelWidgets();
2334 TQWidgetListIt it( *l );
2337 while ( ( wid = it.current() ) != 0 ) {
2339 TQObjectList *l2 = wid->topLevelWidget()->queryList(
"KMMainWidget" );
2340 if (l2 && l2->first()) {
2341 KMMainWidget* kmmw =
dynamic_cast<KMMainWidget *
>( l2->first() );
2353 void KMKernel::slotRunBackgroundTasks()
2357 KConfigGroup generalGroup( config(),
"General" );
2359 if ( generalGroup.readBoolEntry(
"auto-expiring",
true ) ) {
2360 the_folderMgr->expireAllFolders(
false );
2361 the_imapFolderMgr->expireAllFolders(
false );
2362 the_dimapFolderMgr->expireAllFolders(
false );
2366 if ( generalGroup.readBoolEntry(
"auto-compaction",
true ) ) {
2367 the_folderMgr->compactAllFolders(
false );
2369 the_dimapFolderMgr->compactAllFolders(
false );
2373 #ifdef DEBUG_SCHEDULER // for debugging, see jobscheduler.h
2374 mBackgroundTasksTimer->start( 60 * 1000,
true );
2376 mBackgroundTasksTimer->start( 4 * 60 * 60 * 1000,
true );
2383 the_folderMgr->expireAllFolders(
true );
2384 the_imapFolderMgr->expireAllFolders(
true );
2385 the_dimapFolderMgr->expireAllFolders(
true );
2390 the_folderMgr->compactAllFolders(
true );
2392 the_dimapFolderMgr->compactAllFolders(
true );
2397 KMFolder * folder = the_folderMgr->findIdString( idString );
2399 folder = the_imapFolderMgr->findIdString( idString );
2401 folder = the_dimapFolderMgr->findIdString( idString );
2403 folder = the_searchFolderMgr->findIdString( idString );
2409 return KIMProxy::instance( kapp->dcopClient() );
2414 mMailCheckAborted =
false;
2419 return mMailCheckAborted;
2424 mMailCheckAborted =
true;
2427 bool KMKernel::canQueryClose()
2429 if ( KMMainWidget::mainWidgetList() &&
2430 KMMainWidget::mainWidgetList()->count() > 1 )
2436 if ( !systray || GlobalSettings::closeDespiteSystemTray() )
2438 if ( systray->mode() == GlobalSettings::EnumSystemTrayPolicy::ShowAlways ) {
2439 systray->hideKMail();
2441 }
else if ( ( systray->mode() == GlobalSettings::EnumSystemTrayPolicy::ShowOnUnread ) && ( systray->hasUnreadMail() )) {
2443 systray->hideKMail();
2451 mTimeOfLastMessageCountChange = ::time( 0 );
2454 int KMKernel::timeOfLastMessageCountChange()
const
2456 return mTimeOfLastMessageCountChange;
2460 static bool walletOpenFailed =
false;
2461 if ( mWallet && mWallet->isOpen() )
2464 if ( !Wallet::isEnabled() || walletOpenFailed )
2469 if ( tqApp->activeWindow() )
2470 window = tqApp->activeWindow()->winId();
2475 mWallet = Wallet::openWallet( Wallet::NetworkWallet(), window );
2478 walletOpenFailed =
true;
2482 if ( !mWallet->hasFolder(
"kmail" ) )
2483 mWallet->createFolder(
"kmail" );
2484 mWallet->setFolder(
"kmail" );
2491 TQValueList<TQGuardedPtr<KMFolder> > folders;
2492 folderMgr()->createFolderList(&names, &folders);
2493 imapFolderMgr()->createFolderList(&names, &folders);
2494 dimapFolderMgr()->createFolderList(&names, &folders);
2495 searchFolderMgr()->createFolderList(&names, &folders);
2500 KMFolder *KMKernel::currentFolder() {
2503 if ( widget && widget->folderTree() ) {
2504 folder = widget->folderTree()->currentFolder();
2511 KMail::MessageSender * KMKernel::msgSender() {
return the_msgSender; }
2513 #include "kmkernel.moc"