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 <libtdepim/tdefileio.h> 34 #include "kmversion.h" 35 #include "kmreaderwin.h" 36 #include "kmmainwidget.h" 37 #include "kmfoldertree.h" 38 #include "recentaddresses.h" 39 using TDERecentAddress::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" 48 #include <mimelib/enum.h> 51 #include "kmailicalifaceimpl.h" 52 #include "mailserviceimpl.h" 53 using KMail::MailServiceImpl;
54 #include "mailcomposerIface.h" 55 #include "folderIface.h" 56 using KMail::FolderIface;
57 #include "jobscheduler.h" 58 #include "templateparser.h" 60 #include <tdeapplication.h> 61 #include <tdemessagebox.h> 62 #include <knotifyclient.h> 63 #include <kstaticdeleter.h> 64 #include <kstandarddirs.h> 65 #include <tdeconfig.h> 66 #include <kprogress.h> 67 #include <kpassivepopup.h> 68 #include <dcopclient.h> 69 #include <ksystemtray.h> 72 #include <tdeio/netaccess.h> 73 #include <tdewallet.h> 74 using TDEWallet::Wallet;
75 #include "actionscheduler.h" 77 #include <qutf7codec.h> 80 #include <tqwidgetlist.h> 81 #include <tqobjectlist.h> 83 #include <sys/types.h> 93 #include <tdecmdlineargs.h> 94 #include <tdestartupinfo.h> 97 static bool s_askingToGoOnline =
false;
102 KMKernel::KMKernel (TQObject *parent,
const char *name) :
103 DCOPObject(
"KMailIface"), TQObject(parent, name),
104 mIdentityManager(0), mConfigureDialog(0),
105 mContextMenuShown( false ), mWallet( 0 )
107 kdDebug(5006) <<
"KMKernel::KMKernel" << endl;
109 the_startingUp =
true;
110 closed_by_user =
true;
111 the_firstInstance =
true;
115 the_outboxFolder = 0;
118 the_draftsFolder = 0;
119 the_templatesFolder = 0;
122 the_imapFolderMgr = 0;
123 the_dimapFolderMgr = 0;
124 the_searchFolderMgr = 0;
128 the_popFilterMgr = 0;
129 the_filterActionDict = 0;
132 mMailCheckAborted =
false;
139 GlobalSettings::self();
152 if ( !TQTextCodec::codecForName(
"utf-7") ) {
153 kdDebug(5006) <<
"No TQt-native utf-7 codec found; registering TQUtf7Codec from libtdenetwork" << endl;
154 (void)
new TQUtf7Codec();
160 if ( TQCString(TQTextCodec::codecForLocale()->name()).lower() ==
"eucjp" )
162 netCodec = TQTextCodec::codecForName(
"jis7");
167 netCodec = TQTextCodec::codecForLocale();
169 mMailService =
new MailServiceImpl();
171 connectDCOPSignal( 0, 0,
"kmailSelectFolder(TQString)",
172 "selectFolder(TQString)",
false );
174 #ifdef __TDE_HAVE_TDEHWLIB 175 mNetworkManager = TDEGlobal::networkManager();
176 if (mNetworkManager) {
177 connect( mNetworkManager, TQT_SIGNAL( networkDeviceStateChanged( TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString ) ),
178 this, TQT_SLOT( slotNetworkStateChanged( TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString ) ) );
179 if (networkStateConnected()) {
189 KMKernel::~KMKernel ()
191 TQMap<TDEIO::Job*, putData>::Iterator it = mPutJobs.begin();
192 while ( it != mPutJobs.end() )
194 TDEIO::Job *job = it.key();
195 mPutJobs.remove( it );
197 it = mPutJobs.begin();
205 GlobalSettings::self()->writeConfig();
209 kdDebug(5006) <<
"KMKernel::~KMKernel" << endl;
214 TQString to, cc, bcc, subj, body;
215 QCStringList customHeaders;
217 KURL::List attachURLs;
219 bool checkMail =
false;
220 bool viewOnly =
false;
221 bool calledWithSession =
false;
224 TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs();
225 if (!args->getOption(
"subject").isNull())
227 subj = TQString::fromLocal8Bit(args->getOption(
"subject"));
235 if ( subj ==
"ession" ) {
237 calledWithSession =
true;
243 if (!args->getOption(
"cc").isNull())
246 cc = TQString::fromLocal8Bit(args->getOption(
"cc"));
249 if (!args->getOption(
"bcc").isNull())
252 bcc = TQString::fromLocal8Bit(args->getOption(
"bcc"));
255 if (!args->getOption(
"msg").isNull())
258 messageFile.setPath( TQString::fromLocal8Bit(args->getOption(
"msg")) );
261 if (!args->getOption(
"body").isNull())
264 body = TQString::fromLocal8Bit(args->getOption(
"body"));
267 QCStringList attachList = args->getOptionList(
"attach");
268 if (!attachList.isEmpty())
271 for ( QCStringList::Iterator it = attachList.begin() ; it != attachList.end() ; ++it )
272 if ( !(*it).isEmpty() )
273 attachURLs += KURL( TQString::fromLocal8Bit( *it ) );
276 customHeaders = args->getOptionList(
"header");
278 if (args->isSet(
"composer"))
281 if (args->isSet(
"check"))
284 if ( !args->getOption(
"view" ).isNull() ) {
286 const TQString filename =
287 TQString::fromLocal8Bit( args->getOption(
"view" ) );
288 messageFile = KURL::fromPathOrURL( filename );
289 if ( !messageFile.isValid() ) {
290 messageFile = KURL();
291 messageFile.setPath( filename );
295 if ( !calledWithSession ) {
298 for(
int i= 0; i < args->count(); i++)
300 if (strncasecmp(args->arg(i),
"mailto:",7)==0)
301 to += args->url(i).path() +
", ";
303 TQString tmpArg = TQString::fromLocal8Bit( args->arg(i) );
312 if ( !to.isEmpty() ) {
314 to.truncate( to.length() - 2 );
318 if ( !calledWithSession )
321 if ( !noArgsOpensReader && !mailto && !checkMail && !viewOnly )
325 viewMessage( messageFile );
327 action( mailto, checkMail, to, cc, bcc, subj, body, messageFile,
328 attachURLs, customHeaders );
337 if ( !kmkernel->askToGoOnline() )
339 kmkernel->acctMgr()->checkMail(
false);
342 TQStringList KMKernel::accounts()
344 if( kmkernel->acctMgr() )
345 return kmkernel->acctMgr()->getAccounts();
346 return TQStringList();
349 void KMKernel::checkAccount (
const TQString &account)
351 kdDebug(5006) <<
"KMKernel::checkMail called" << endl;
353 KMAccount* acct = kmkernel->acctMgr()->findByName(account);
355 kmkernel->acctMgr()->singleCheckMail(acct,
false);
358 void KMKernel::loadProfile(
const TQString& )
362 void KMKernel::saveToProfile(
const TQString& )
const 366 void KMKernel::openReader(
bool onlyCheck )
369 TDEMainWindow *ktmw = 0;
370 kdDebug(5006) <<
"KMKernel::openReader called" << endl;
372 if (TDEMainWindow::memberList)
373 for (ktmw = TDEMainWindow::memberList->first(); ktmw;
374 ktmw = TDEMainWindow::memberList->next())
375 if (ktmw->isA(
"KMMainWin"))
380 mWin = (KMMainWin *) ktmw;
381 activate = !onlyCheck;
385 mWin =
new KMMainWin;
393 #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY 394 TDEStartupInfo::setNewStartupId( mWin, kapp->startupId() );
400 const TQString &bcc,
const TQString &subject,
401 const TQString &body,
int hidden,
402 const KURL &messageFile,
403 const KURL::List &attachURLs,
404 const QCStringList &customHeaders)
406 kdDebug(5006) <<
"KMKernel::openComposer called" << endl;
413 msg->setTo( KMMsgBase::decodeRFC2047String( to.latin1() ) );
415 msg->setCc( KMMsgBase::decodeRFC2047String( cc.latin1() ) );
417 msg->setBcc( KMMsgBase::decodeRFC2047String( bcc.latin1() ) );
418 if (!subject.isEmpty()) msg->setSubject(subject);
419 if (!messageFile.isEmpty() && messageFile.isLocalFile()) {
420 TQCString str = KPIM::kFileToString( messageFile.path(),
true, false );
421 if( !str.isEmpty() ) {
422 msg->
setBody( TQString(TQString::fromLocal8Bit( str )).utf8() );
425 parser.process( NULL, NULL );
428 else if (!body.isEmpty())
435 parser.process( NULL, NULL );
438 if (!customHeaders.isEmpty())
440 for ( QCStringList::ConstIterator it = customHeaders.begin() ; it != customHeaders.end() ; ++it )
441 if ( !(*it).isEmpty() )
443 const int pos = (*it).find(
':' );
446 TQCString header, value;
447 header = (*it).left( pos ).stripWhiteSpace();
448 value = (*it).mid( pos+1 ).stripWhiteSpace();
449 if ( !header.isEmpty() && !value.isEmpty() )
455 KMail::Composer * cWin = KMail::makeComposer( msg );
456 cWin->setCharset(
"",
true);
457 for ( KURL::List::ConstIterator it = attachURLs.begin() ; it != attachURLs.end() ; ++it )
458 cWin->addAttach((*it));
463 #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY 464 TDEStartupInfo::setNewStartupId( cWin, kapp->startupId() );
472 const TQString &bcc,
const TQString &subject,
473 const TQString &body,
int hidden,
474 const TQString &attachName,
475 const TQCString &attachCte,
476 const TQCString &attachData,
477 const TQCString &attachType,
478 const TQCString &attachSubType,
479 const TQCString &attachParamAttr,
480 const TQString &attachParamValue,
481 const TQCString &attachContDisp )
483 kdDebug(5006) <<
"KMKernel::openComposer called (deprecated version)" << endl;
485 return openComposer ( to, cc, bcc, subject, body, hidden,
486 attachName, attachCte, attachData,
487 attachType, attachSubType, attachParamAttr,
488 attachParamValue, attachContDisp, TQCString() );
492 const TQString &bcc,
const TQString &subject,
493 const TQString &body,
int hidden,
494 const TQString &attachName,
495 const TQCString &attachCte,
496 const TQCString &attachData,
497 const TQCString &attachType,
498 const TQCString &attachSubType,
499 const TQCString &attachParamAttr,
500 const TQString &attachParamValue,
501 const TQCString &attachContDisp,
502 const TQCString &attachCharset )
504 kdDebug(5006) <<
"KMKernel::openComposer called (deprecated version)" << endl;
505 return openComposer ( to, cc, bcc, subject, body, hidden,
506 attachName, attachCte, attachData,
507 attachType, attachSubType, attachParamAttr,
508 attachParamValue, attachContDisp, attachCharset, 0 );
512 const TQString &bcc,
const TQString &subject,
513 const TQString &body,
int hidden,
514 const TQString &attachName,
515 const TQCString &attachCte,
516 const TQCString &attachData,
517 const TQCString &attachType,
518 const TQCString &attachSubType,
519 const TQCString &attachParamAttr,
520 const TQString &attachParamValue,
521 const TQCString &attachContDisp,
522 const TQCString &attachCharset,
523 unsigned int identity )
525 kdDebug(5006) <<
"KMKernel::openComposer()" << endl;
528 KMMessagePart *msgPart = 0;
531 if ( !cc.isEmpty() ) msg->setCc(cc);
532 if ( !bcc.isEmpty() ) msg->setBcc(bcc);
533 if ( !subject.isEmpty() ) msg->setSubject(subject);
534 if ( !to.isEmpty() ) msg->setTo(to);
535 if ( identity > 0 ) msg->
setHeaderField(
"X-KMail-Identity", TQString::number( identity ) );
536 if ( !body.isEmpty() ) {
540 parser.process( NULL, NULL );
543 bool iCalAutoSend =
false;
544 bool noWordWrap =
false;
545 bool isICalInvitation =
false;
546 TDEConfigGroup options( config(),
"Groupware" );
547 if ( !attachData.isEmpty() ) {
548 isICalInvitation = attachName ==
"cal.ics" &&
549 attachType ==
"text" &&
550 attachSubType ==
"calendar" &&
551 attachParamAttr ==
"method";
553 if ( isICalInvitation && bcc.isEmpty() )
555 if ( isICalInvitation &&
556 GlobalSettings::self()->legacyBodyInvites() ) {
560 TQString(
"text/calendar; method=%1; " 561 "charset=\"utf-8\"" ).
562 arg( attachParamValue ) );
568 msgPart =
new KMMessagePart;
569 msgPart->setName( attachName );
570 msgPart->setCteStr( attachCte );
571 msgPart->setBodyEncoded( attachData );
572 msgPart->setTypeStr( attachType );
573 msgPart->setSubtypeStr( attachSubType );
574 msgPart->setParameter( attachParamAttr, attachParamValue );
575 if( ! GlobalSettings::self()->exchangeCompatibleInvitations() ) {
576 msgPart->setContentDisposition( attachContDisp );
578 if( !attachCharset.isEmpty() && (msgPart->type() == DwMime::kTypeText) ) {
581 msgPart->setCharset( attachCharset );
584 TDEConfigGroup options( config(),
"Groupware" );
585 iCalAutoSend = options.readBoolEntry(
"AutomaticSending",
true );
589 KMail::Composer * cWin = KMail::makeComposer();
590 cWin->setMsg( msg, !isICalInvitation );
591 cWin->setSigningAndEncryptionDisabled( isICalInvitation
592 && GlobalSettings::self()->legacyBodyInvites() );
593 cWin->setAutoDelete(
true );
595 cWin->disableWordWrap();
597 cWin->setCharset(
"",
true );
599 cWin->addAttach(msgPart);
601 if ( isICalInvitation ) {
602 cWin->disableRecipientNumberCheck();
603 cWin->disableForgottenAttachmentsCheck();
606 if ( hidden == 0 && !iCalAutoSend ) {
610 #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY 611 TDEStartupInfo::setNewStartupId( cWin, kapp->startupId() );
614 cWin->setAutoDeleteWindow(
true );
624 TQStringList::const_iterator it = availTransports.find( transport );
625 if ( it == availTransports.end() ) {
626 kdWarning() <<
"The transport you entered is not available" << endl;
629 GlobalSettings::self()->setDefaultTransport( transport );
633 const TQString &bcc,
const TQString &subject,
634 const TQString &body,
bool hidden)
639 if (!cc.isEmpty()) msg->setCc(cc);
640 if (!bcc.isEmpty()) msg->setBcc(bcc);
641 if (!subject.isEmpty()) msg->setSubject(subject);
642 if (!to.isEmpty()) msg->setTo(to);
643 if (!body.isEmpty()) {
647 parser.process( NULL, NULL );
650 KMail::Composer * cWin = KMail::makeComposer( msg );
651 cWin->setCharset(
"",
true);
656 #if defined TQ_WS_X11 && ! defined K_WS_TQTONLY 657 TDEStartupInfo::setNewStartupId( cWin, kapp->startupId() );
661 return DCOPRef( cWin->asMailComposerIFace() );
670 const KURL &attachURL)
672 KMail::Composer * win = 0;
679 folder = currentFolder();
680 id = folder ? folder->identity() : 0;
687 if (!to.isEmpty()) msg->setTo(to);
688 if (!cc.isEmpty()) msg->setCc(cc);
689 if (!bcc.isEmpty()) msg->setBcc(bcc);
693 parser.process( NULL, folder );
694 win = makeComposer( msg,
id );
697 parser.process( NULL, folder );
698 win = makeComposer( msg );
702 if(!attachURL.isEmpty() && attachURL.isValid()) {
703 win->addAttach(attachURL);
710 return DCOPRef( win->asMailComposerIFace() );
713 int KMKernel::viewMessage(
const KURL & messageFile )
715 KMOpenMsgCommand *openCommand =
new KMOpenMsgCommand( 0, messageFile );
717 openCommand->start();
727 msg->setSubject( i18n(
"Certificate Signature Request" ) );
728 if (!to.isEmpty()) msg->setTo(to);
730 msg->
setBody( i18n(
"Please create a certificate from attachment and return to sender." ).utf8() );
732 KMail::Composer * cWin = KMail::makeComposer( msg );
733 cWin->setCharset(
"",
true);
734 cWin->slotSetAlwaysSend(
true );
735 if (!certData.isEmpty()) {
736 KMMessagePart *msgPart =
new KMMessagePart;
737 msgPart->setName(
"smime.p10");
738 msgPart->setCteStr(
"base64");
739 msgPart->setBodyEncodedBinary(certData);
740 msgPart->setTypeStr(
"application");
741 msgPart->setSubtypeStr(
"pkcs10");
742 msgPart->setContentDisposition(
"attachment; filename=smime.p10");
743 cWin->addAttach(msgPart);
750 KMMsgStatus KMKernel::strToStatus(
const TQString &flags)
752 KMMsgStatus status = 0;
753 if (!flags.isEmpty()) {
754 for (uint n = 0; n < flags.length() ; n++) {
757 status |= KMMsgStatusNew;
760 status |= KMMsgStatusUnread;
763 status |= KMMsgStatusOld;
766 status |= KMMsgStatusRead;
769 status |= KMMsgStatusDeleted;
772 status |= KMMsgStatusReplied;
775 status |= KMMsgStatusForwarded;
778 status |= KMMsgStatusQueued;
781 status |= KMMsgStatusTodo;
784 status |= KMMsgStatusSent;
787 status |= KMMsgStatusFlag;
790 status |= KMMsgStatusWatched;
793 status |= KMMsgStatusIgnored;
796 status |= KMMsgStatusSpam;
799 status |= KMMsgStatusHam;
802 status |= KMMsgStatusHasAttach;
805 status |= KMMsgStatusHasNoAttach;
816 const TQString & MsgStatusFlags)
818 return dcopAddMessage(foldername, KURL(msgUrlString), MsgStatusFlags);
822 const TQString & MsgStatusFlags)
824 kdDebug(5006) <<
"KMKernel::dcopAddMessage called" << endl;
826 if ( foldername.isEmpty() || foldername.startsWith(
"."))
830 bool readFolderMsgIds =
false;
831 TQString _foldername = foldername.stripWhiteSpace();
832 _foldername = _foldername.replace(
'\\',
"");
834 if ( foldername != mAddMessageLastFolder ) {
835 mAddMessageMsgIds.clear();
836 readFolderMsgIds =
true;
837 mAddMessageLastFolder = foldername;
840 if (!msgUrl.isEmpty() && msgUrl.isLocalFile()) {
849 const TQCString messageText =
850 KPIM::kFileToString( msgUrl.path(),
true, false );
851 if ( messageText.isEmpty() )
855 msg->fromString( messageText );
857 if (readFolderMsgIds) {
858 if ( foldername.contains(
"/")) {
859 TQString tmp_fname =
"";
864 TQStringList subFList = TQStringList::split(
"/",_foldername,
false);
866 for ( TQStringList::Iterator it = subFList.begin(); it != subFList.end(); ++it ) {
867 TQString _newFolder = *it;
868 if(_newFolder.startsWith(
"."))
return -1;
871 folder = the_folderMgr->findOrCreate(*it,
false);
874 tmp_fname =
"/" + *it;
879 tmp_fname +=
"/" + *it;
880 if(!the_folderMgr->getFolderByURL( tmp_fname )) {
881 folder = the_folderMgr->createFolder(*it,
false, folder->
folderType(), subfolder);
884 if(!(folder = the_folderMgr->getFolderByURL( tmp_fname )))
return -1;
888 mAddMsgCurrentFolder = the_folderMgr->getFolderByURL( tmp_fname );
889 if(!folder)
return -1;
892 mAddMsgCurrentFolder = the_folderMgr->findOrCreate(_foldername,
false);
896 if ( mAddMsgCurrentFolder ) {
897 if (readFolderMsgIds) {
922 mAddMsgCurrentFolder->
open(
"dcopadd");
923 for( i=0; i<mAddMsgCurrentFolder->count(); i++) {
924 KMMsgBase *mb = mAddMsgCurrentFolder->getMsgBase(i);
925 TQString
id = mb->msgIdMD5();
926 if (
id.isEmpty() ) {
929 id = mb->fromStrip();
937 if ( !
id.isEmpty() ) {
938 mAddMessageMsgIds.append(
id);
941 mAddMsgCurrentFolder->close(
"dcopadd");
944 TQString msgId = msg->msgIdMD5();
945 if ( msgId.isEmpty()) {
947 if ( msgId.isEmpty() )
948 msgId = msg->fromStrip();
949 if ( msgId.isEmpty() )
950 msgId = msg->toStrip();
955 int k = mAddMessageMsgIds.findIndex( msgId );
959 if ( !msgId.isEmpty() ) {
960 mAddMessageMsgIds.append( msgId );
963 if ( !MsgStatusFlags.isEmpty() ) {
964 KMMsgStatus status = strToStatus(MsgStatusFlags);
969 if ( mAddMsgCurrentFolder->addMsg( msg, &index ) == 0 ) {
970 mAddMsgCurrentFolder->unGetMsg( index );
992 mAddMessageMsgIds.clear();
993 mAddMessageLastFolder = TQString();
997 const TQString & msgUrlString,
998 const TQString & MsgStatusFlags)
1000 return dcopAddMessage_fastImport(foldername, KURL(msgUrlString), MsgStatusFlags);
1004 const KURL & msgUrl,
1005 const TQString & MsgStatusFlags)
1009 kdDebug(5006) <<
"KMKernel::dcopAddMessage_fastImport called" << endl;
1011 if ( foldername.isEmpty() || foldername.startsWith(
"."))
1015 bool createNewFolder =
false;
1017 TQString _foldername = foldername.stripWhiteSpace();
1018 _foldername = _foldername.replace(
'\\',
"");
1020 if ( foldername != mAddMessageLastFolder ) {
1021 createNewFolder =
true;
1022 mAddMessageLastFolder = foldername;
1026 if ( !msgUrl.isEmpty() && msgUrl.isLocalFile() ) {
1027 const TQCString messageText =
1028 KPIM::kFileToString( msgUrl.path(),
true, false );
1029 if ( messageText.isEmpty() )
1033 msg->fromString( messageText );
1035 if (createNewFolder) {
1036 if ( foldername.contains(
"/")) {
1037 TQString tmp_fname =
"";
1042 TQStringList subFList = TQStringList::split(
"/",_foldername,
false);
1044 for ( TQStringList::Iterator it = subFList.begin(); it != subFList.end(); ++it ) {
1045 TQString _newFolder = *it;
1046 if(_newFolder.startsWith(
"."))
return -1;
1049 folder = the_folderMgr->findOrCreate(*it,
false);
1052 tmp_fname =
"/" + *it;
1057 tmp_fname +=
"/" + *it;
1058 if(!the_folderMgr->getFolderByURL( tmp_fname )) {
1059 folder = the_folderMgr->createFolder(*it,
false, folder->
folderType(), subfolder);
1061 if(!(folder = the_folderMgr->getFolderByURL( tmp_fname )))
return -1;
1065 mAddMsgCurrentFolder = the_folderMgr->getFolderByURL( tmp_fname );
1066 if(!folder)
return -1;
1069 mAddMsgCurrentFolder = the_folderMgr->findOrCreate(_foldername,
false);
1073 if ( mAddMsgCurrentFolder ) {
1076 if( !MsgStatusFlags.isEmpty() ) {
1077 KMMsgStatus status = strToStatus(MsgStatusFlags);
1081 if ( mAddMsgCurrentFolder->addMsg( msg, &index ) == 0 ) {
1082 mAddMsgCurrentFolder->unGetMsg( index );
1099 void KMKernel::showImportArchiveDialog()
1101 KMMainWidget *mainWidget = getKMMainWidget();
1102 KMail::ImportArchiveDialog *importDialog =
new KMail::ImportArchiveDialog( mainWidget, WDestructiveClose );
1103 importDialog->setFolder( mainWidget->folderTree()->currentFolder() );
1104 importDialog->show();
1107 TQStringList KMKernel::folderList()
const 1109 TQStringList folders;
1110 const TQString localPrefix =
"/Local";
1111 folders << localPrefix;
1112 the_folderMgr->getFolderURLS( folders, localPrefix );
1113 the_imapFolderMgr->getFolderURLS( folders );
1114 the_dimapFolderMgr->getFolderURLS( folders );
1118 DCOPRef KMKernel::getFolder(
const TQString& vpath )
1120 const TQString localPrefix =
"/Local";
1121 if ( the_folderMgr->getFolderByURL( vpath ) )
1122 return DCOPRef(
new FolderIface( vpath ) );
1123 else if ( vpath.startsWith( localPrefix ) &&
1124 the_folderMgr->getFolderByURL( vpath.mid( localPrefix.length() ) ) )
1125 return DCOPRef(
new FolderIface( vpath.mid( localPrefix.length() ) ) );
1126 else if ( the_imapFolderMgr->getFolderByURL( vpath ) )
1127 return DCOPRef(
new FolderIface( vpath ) );
1128 else if ( the_dimapFolderMgr->getFolderByURL( vpath ) )
1129 return DCOPRef(
new FolderIface( vpath ) );
1133 void KMKernel::raise()
1135 DCOPRef kmail(
"kmail",
"kmail" );
1136 kmail.call(
"newInstance" );
1141 KMMainWidget *mainWidget = 0;
1142 if (TDEMainWindow::memberList) {
1143 TDEMainWindow *win = 0;
1147 for (win = TDEMainWindow::memberList->first(); win;
1148 win = TDEMainWindow::memberList->next()) {
1150 l = win->queryList(
"KMMainWidget");
1151 if (l && l->first()) {
1152 mainWidget =
dynamic_cast<KMMainWidget *
>(l->first());
1153 if (win->isActiveWindow())
1163 if (!folder || (idx == -1))
1166 KMMsgBase *msgBase = folder->
getMsgBase(idx);
1169 bool unGet = !msgBase->isMessage();
1172 KMReaderMainWin *win =
new KMReaderMainWin(
false,
false );
1174 newMessage->setParent( msg->parent() );
1177 win->showMsg( GlobalSettings::self()->overrideCharacterEncoding(), newMessage );
1193 if (!folder || (idx == -1))
1196 KMMsgBase *msgBase = folder->
getMsgBase(idx);
1199 bool unGet = !msgBase->isMessage();
1201 TQString result = msg->
from();
1207 TQString KMKernel::debugScheduler()
1209 TQString res = KMail::ActionScheduler::debug();
1213 TQString KMKernel::debugSernum( TQ_UINT32 serialNumber )
1216 if (serialNumber != 0) {
1223 if (folder && (idx != -1)) {
1228 res.append( TQString(
" subject %s,\n sender %s,\n date %s.\n" )
1229 .arg( msg->subject() )
1230 .arg( msg->fromStrip() )
1231 .arg( msg->dateStr() ) );
1233 res.append( TQString(
"Invalid serial number." ) );
1236 res.append( TQString(
"Invalid serial number." ) );
1245 mBackgroundTasksTimer->stop();
1246 mJobScheduler->pause();
1251 mJobScheduler->resume();
1252 mBackgroundTasksTimer->start( 4 * 60 * 60 * 1000,
true );
1257 if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Offline )
1260 GlobalSettings::setNetworkState( GlobalSettings::EnumNetworkState::Offline );
1261 BroadcastStatus::instance()->setStatusMsg( i18n(
"KMail is set to be offline; all network jobs are suspended"));
1262 emit onlineStatusChanged( (GlobalSettings::EnumNetworkState::type)GlobalSettings::networkState() );
1267 if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Online )
1270 GlobalSettings::setNetworkState( GlobalSettings::EnumNetworkState::Online );
1271 BroadcastStatus::instance()->setStatusMsg( i18n(
"KMail is set to be online; all network jobs resumed"));
1272 emit onlineStatusChanged( (GlobalSettings::EnumNetworkState::type)GlobalSettings::networkState() );
1274 if ( kmkernel->msgSender() && kmkernel->msgSender()->sendImmediate() ) {
1275 kmkernel->msgSender()->sendQueued();
1281 if ( GlobalSettings::self()->networkState() == GlobalSettings::EnumNetworkState::Offline )
1290 if ( s_askingToGoOnline ) {
1294 if ( kmkernel->isOffline() ) {
1295 s_askingToGoOnline =
true;
1298 i18n(
"KMail is currently in offline mode. " 1299 "How do you want to proceed?"),
1300 i18n(
"Online/Offline"),
1301 i18n(
"Work Online"),
1302 i18n(
"Work Offline"));
1304 s_askingToGoOnline =
false;
1305 if( rc == KMessageBox::No ) {
1308 kmkernel->resumeNetworkJobs();
1318 void KMKernel::quit()
1369 void KMKernel::testDir(
const char *_name)
1371 TQString foldersPath = TQDir::homeDirPath() + TQString( _name );
1372 TQFileInfo info( foldersPath );
1373 if ( !info.exists() ) {
1374 if ( ::mkdir( TQFile::encodeName( foldersPath ) , S_IRWXU ) == -1 ) {
1375 KMessageBox::sorry(0, i18n(
"KMail could not create folder '%1';\n" 1376 "please make sure that you can view and " 1377 "modify the content of the folder '%2'.")
1378 .arg( foldersPath ).arg( TQDir::homeDirPath() ) );
1382 if ( !info.isDir() || !info.isReadable() || !info.isWritable() ) {
1383 KMessageBox::sorry(0, i18n(
"The permissions of the folder '%1' are " 1385 "please make sure that you can view and modify " 1386 "the content of this folder.")
1387 .arg( foldersPath ) );
1395 void KMKernel::recoverDeadLetters()
1397 TQDir dir( localDataPath() +
"autosave/cur" );
1398 if ( !dir.exists() ) {
1399 kdWarning(5006) <<
"Autosave directory " << dir.path() <<
" not found!" << endl;
1403 const TQStringList entryList = dir.entryList( TQDir::Files | TQDir::NoSymLinks, TQDir::Unsorted );
1404 for (
unsigned int i = 0; i < entryList.size(); i++ ) {
1405 const TQString fileName = entryList[i];
1406 TQFile file( dir.path() +
'/' + fileName );
1407 if ( !file.open( IO_ReadOnly ) ) {
1408 kdWarning(5006) <<
"Unable to open autosave file " << fileName << endl;
1411 const TQByteArray msgData = file.readAll();
1414 if ( msgData.isEmpty() ) {
1415 kdWarning(5006) <<
"autosave file " << fileName <<
" is empty!" << endl;
1420 msg->fromByteArray( msgData );
1421 KMail::Composer * win = KMail::makeComposer();
1422 win->setMsg( msg,
false,
false,
true );
1423 win->setAutoSaveFilename( fileName );
1429 void KMKernel::initFolders(TDEConfig* cfg)
1433 name = cfg->readEntry(
"inboxFolder");
1439 if (name.isEmpty()) name = I18N_NOOP(
"inbox");
1441 the_inboxFolder = (
KMFolder*)the_folderMgr->findOrCreate(name);
1443 if (the_inboxFolder->canAccess() != 0) {
1444 emergencyExit( i18n(
"You do not have read/write permission to your inbox folder.") );
1447 the_inboxFolder->setSystemFolder(
true);
1448 if ( the_inboxFolder->userWhoField().isEmpty() )
1449 the_inboxFolder->setUserWhoField( TQString() );
1452 the_outboxFolder = the_folderMgr->findOrCreate(cfg->readEntry(
"outboxFolder", I18N_NOOP(
"outbox")));
1453 if (the_outboxFolder->canAccess() != 0) {
1454 emergencyExit( i18n(
"You do not have read/write permission to your outbox folder.") );
1456 the_outboxFolder->setNoChildren(
true);
1458 the_outboxFolder->setSystemFolder(
true);
1459 if ( the_outboxFolder->userWhoField().isEmpty() )
1460 the_outboxFolder->setUserWhoField( TQString() );
1469 the_outboxFolder->open(
"kmkernel");
1471 the_sentFolder = the_folderMgr->findOrCreate(cfg->readEntry(
"sentFolder", I18N_NOOP(
"sent-mail")));
1472 if (the_sentFolder->canAccess() != 0) {
1473 emergencyExit( i18n(
"You do not have read/write permission to your sent-mail folder.") );
1475 the_sentFolder->setSystemFolder(
true);
1476 if ( the_sentFolder->userWhoField().isEmpty() )
1477 the_sentFolder->setUserWhoField( TQString() );
1480 the_trashFolder = the_folderMgr->findOrCreate(cfg->readEntry(
"trashFolder", I18N_NOOP(
"trash")));
1481 if (the_trashFolder->canAccess() != 0) {
1482 emergencyExit( i18n(
"You do not have read/write permission to your trash folder.") );
1484 the_trashFolder->setSystemFolder(
true );
1485 if ( the_trashFolder->userWhoField().isEmpty() )
1486 the_trashFolder->setUserWhoField( TQString() );
1489 the_draftsFolder = the_folderMgr->findOrCreate(cfg->readEntry(
"draftsFolder", I18N_NOOP(
"drafts")));
1490 if (the_draftsFolder->canAccess() != 0) {
1491 emergencyExit( i18n(
"You do not have read/write permission to your drafts folder.") );
1493 the_draftsFolder->setSystemFolder(
true );
1494 if ( the_draftsFolder->userWhoField().isEmpty() )
1495 the_draftsFolder->setUserWhoField( TQString() );
1496 the_draftsFolder->open(
"kmkernel");
1498 the_templatesFolder =
1499 the_folderMgr->findOrCreate( cfg->readEntry(
"templatesFolder",
1500 I18N_NOOP(
"templates") ) );
1501 if ( the_templatesFolder->canAccess() != 0 ) {
1502 emergencyExit( i18n(
"You do not have read/write permission to your templates folder.") );
1504 the_templatesFolder->setSystemFolder(
true );
1505 if ( the_templatesFolder->userWhoField().isEmpty() )
1506 the_templatesFolder->setUserWhoField( TQString() );
1507 the_templatesFolder->open(
"kmkernel");
1511 void KMKernel::init()
1513 the_shuttingDown =
false;
1514 the_server_is_ready =
false;
1516 TDEConfig* cfg = KMKernel::config();
1520 TDEConfigGroupSaver saver(cfg,
"General");
1521 the_firstStart = cfg->readBoolEntry(
"first-start",
true);
1522 cfg->writeEntry(
"first-start",
false);
1523 the_previousVersion = cfg->readEntry(
"previous-version");
1524 cfg->writeEntry(
"previous-version", KMAIL_VERSION);
1525 TQString foldersPath = cfg->readPathEntry(
"folders" );
1526 kdDebug(5006) << k_funcinfo <<
"foldersPath (from config): '" << foldersPath <<
"'" << endl;
1528 if ( foldersPath.isEmpty() ) {
1529 foldersPath = localDataPath() +
"mail";
1530 if ( transferMail( foldersPath ) ) {
1531 cfg->writePathEntry(
"folders", foldersPath );
1533 kdDebug(5006) << k_funcinfo <<
"foldersPath (after transferMail): '" << foldersPath <<
"'" << endl;
1539 the_undoStack =
new UndoStack(20);
1540 the_folderMgr =
new KMFolderMgr(foldersPath);
1541 the_imapFolderMgr =
new KMFolderMgr( KMFolderImap::cacheLocation(), KMImapDir);
1542 the_dimapFolderMgr =
new KMFolderMgr( KMFolderCachedImap::cacheLocation(), KMDImapDir);
1543 recreateCorruptIndexFiles();
1545 the_searchFolderMgr =
new KMFolderMgr(locateLocal(
"data",
"kmail/search"), KMSearchDir);
1546 KMFolder *lsf = the_searchFolderMgr->
find( i18n(
"Last Search") );
1548 the_searchFolderMgr->remove( lsf );
1551 the_filterMgr =
new KMFilterMgr();
1552 the_popFilterMgr =
new KMFilterMgr(
true);
1556 the_acctMgr->readConfig();
1557 the_filterMgr->readConfig();
1558 the_popFilterMgr->readConfig();
1559 cleanupImapFolders();
1561 the_msgSender =
new KMSender;
1562 the_server_is_ready =
true;
1563 imProxy()->initialize();
1565 TDEConfigGroupSaver saver(cfg,
"Composer");
1566 if (cfg->readListEntry(
"pref-charsets").isEmpty())
1568 cfg->writeEntry(
"pref-charsets",
"us-ascii,iso-8859-1,locale,utf-8");
1572 mICalIface->readConfig();
1574 #ifdef HAVE_INDEXLIB 1575 the_msgIndex =
new KMMsgIndex(
this);
1581 the_weaver =
new KPIM::ThreadWeaver::Weaver(
this );
1582 the_weaverLogger =
new KPIM::ThreadWeaver::WeaverThreadLogger(
this);
1583 the_weaverLogger->attach (the_weaver);
1586 connect( the_folderMgr, TQT_SIGNAL( folderRemoved(
KMFolder*) ),
1587 this, TQT_SIGNAL( folderRemoved(
KMFolder*) ) );
1588 connect( the_dimapFolderMgr, TQT_SIGNAL( folderRemoved(
KMFolder*) ),
1589 this, TQT_SIGNAL( folderRemoved(
KMFolder*) ) );
1590 connect( the_imapFolderMgr, TQT_SIGNAL( folderRemoved(
KMFolder*) ),
1591 this, TQT_SIGNAL( folderRemoved(
KMFolder*) ) );
1592 connect( the_searchFolderMgr, TQT_SIGNAL( folderRemoved(
KMFolder*) ),
1593 this, TQT_SIGNAL( folderRemoved(
KMFolder*) ) );
1595 mBackgroundTasksTimer =
new TQTimer(
this,
"mBackgroundTasksTimer" );
1596 connect( mBackgroundTasksTimer, TQT_SIGNAL( timeout() ),
this, TQT_SLOT( slotRunBackgroundTasks() ) );
1597 #ifdef DEBUG_SCHEDULER // for debugging, see jobscheduler.h 1598 mBackgroundTasksTimer->start( 10000,
true );
1600 mBackgroundTasksTimer->start( 5 * 60000,
true );
1604 for (
int i = 0; ( codec = TQTextCodec::codecForIndex ( i ) ); i++ ) {
1605 const TQString asciiString(
"azAZ19,.-#+!?=()&" );
1606 const TQCString encodedString = codec->fromUnicode( asciiString );
1607 if ( TQString::fromAscii( encodedString ) != asciiString ) {
1608 mNonAsciiCompatibleCodecs.append( codec );
1613 bool KMKernel::isCodecAsciiCompatible(
const TQTextCodec *codec )
1615 return !mNonAsciiCompatibleCodecs.contains( codec );
1618 void KMKernel::readConfig()
1625 void KMKernel::cleanupImapFolders()
1627 KMAccount *acct = 0;
1628 KMFolderNode *node = the_imapFolderMgr->dir().first();
1631 if (node->isDir() || ((acct = the_acctMgr->find(node->id()))
1632 && ( acct->type() ==
"imap" )) )
1634 node = the_imapFolderMgr->dir().next();
1638 static_cast<KMFolderImap*
>( folder->storage() )->setAlreadyRemoved(
true );
1639 the_imapFolderMgr->
remove(folder);
1640 node = the_imapFolderMgr->dir().first();
1644 node = the_dimapFolderMgr->dir().first();
1647 if (node->isDir() || ((acct = the_acctMgr->find(node->id()))
1648 && ( acct->type() ==
"cachedimap" )) )
1650 node = the_dimapFolderMgr->dir().next();
1652 the_dimapFolderMgr->remove(static_cast<KMFolder*>(node));
1653 node = the_dimapFolderMgr->dir().first();
1657 the_imapFolderMgr->quiet(
true);
1658 for (acct = the_acctMgr->first(); acct; acct = the_acctMgr->next())
1661 KMAcctImap *imapAcct;
1663 if (acct->type() !=
"imap")
continue;
1664 fld =
static_cast<KMFolderImap*
>(the_imapFolderMgr
1665 ->findOrCreate(TQString::number(acct->id()),
false, acct->id())->storage());
1666 fld->setNoContent(
true);
1667 fld->folder()->setLabel(acct->name());
1668 imapAcct =
static_cast<KMAcctImap*
>(acct);
1669 fld->setAccount(imapAcct);
1670 imapAcct->setImapFolder(fld);
1671 fld->close(
"kernel",
true );
1673 the_imapFolderMgr->quiet(
false);
1675 the_dimapFolderMgr->quiet(
true );
1676 for (acct = the_acctMgr->first(); acct; acct = the_acctMgr->next())
1678 KMFolderCachedImap *cfld = 0;
1679 KMAcctCachedImap *cachedImapAcct;
1681 if (acct->type() !=
"cachedimap" )
continue;
1683 KMFolder* fld = the_dimapFolderMgr->
find(TQString::number(acct->id()));
1685 cfld =
static_cast<KMFolderCachedImap*
>( fld->storage() );
1688 cfld =
static_cast<KMFolderCachedImap*
>(the_dimapFolderMgr->createFolder(TQString::number(acct->id()),
1689 false, KMFolderTypeCachedImap)->storage());
1691 KMessageBox::error(0,(i18n(
"Cannot create file `%1' in %2.\nKMail cannot start without it.").arg(acct->name()).arg(the_dimapFolderMgr->basePath())));
1694 cfld->folder()->setId( acct->id() );
1697 cfld->setNoContent(
true);
1698 cfld->folder()->setLabel(acct->name());
1699 cachedImapAcct =
static_cast<KMAcctCachedImap*
>(acct);
1700 cfld->setAccount(cachedImapAcct);
1701 cachedImapAcct->setImapFolder(cfld);
1702 cfld->close(
"kmkernel");
1704 the_dimapFolderMgr->quiet(
false );
1707 void KMKernel::recreateCorruptIndexFiles()
1709 TQValueList<TQGuardedPtr<KMFolder> > folders;
1710 TQValueList<KMFolderIndex*> foldersWithBrokenIndex;
1711 TQStringList strList;
1712 the_folderMgr->createFolderList( &strList, &folders );
1713 the_imapFolderMgr->createFolderList( &strList, &folders );
1714 the_dimapFolderMgr->createFolderList( &strList, &folders );
1715 for (
int i = 0; folders.at(i) != folders.end(); i++ ) {
1717 if ( !folder || folder->isDir() || folder->
isOpened() )
1720 if ( index && index->
indexStatus() != KMFolderIndex::IndexOk ) {
1721 foldersWithBrokenIndex.append( index );
1725 if ( !foldersWithBrokenIndex.isEmpty() ) {
1726 TQStringList folderNames;
1727 for ( uint i = 0; i < foldersWithBrokenIndex.size(); i++ ) {
1728 folderNames << foldersWithBrokenIndex[i]->label();
1731 KMessageBox::informationList( 0, i18n(
"There is a problem with the mail index of the following " 1732 "folders, the indices will now be regenerated.\n" 1733 "This can happen because the index files are out of date, missing or corrupted.\n" 1734 "Contact your administrator if this happens frequently.\n" 1735 "Some information, like status flags, might get lost." ),
1736 folderNames, i18n(
"Problem with mail indices" ) );
1738 for ( uint i = 0; i < foldersWithBrokenIndex.size(); i++ ) {
1739 foldersWithBrokenIndex[i]->silentlyRecreateIndex();
1744 bool KMKernel::doSessionManagement()
1748 if (kapp->isRestored()){
1750 while (KMMainWin::canBeRestored(n)){
1752 if (KMMainWin::classNameOfToplevel(n) ==
"KMMainWin")
1753 (
new KMMainWin)->restore(n);
1761 void KMKernel::closeAllKMailWindows()
1763 if (!TDEMainWindow::memberList)
return;
1764 TQPtrListIterator<TDEMainWindow> it(*TDEMainWindow::memberList);
1765 TDEMainWindow *window = 0;
1766 while ((window = it.current()) != 0) {
1768 if (window->isA(
"KMMainWindow") ||
1769 window->inherits(
"KMail::SecondaryWindow"))
1770 window->close(
true );
1774 void KMKernel::cleanup(
void)
1777 the_shuttingDown =
true;
1778 closeAllKMailWindows();
1782 delete the_filterMgr;
1784 delete the_msgSender;
1786 delete the_filterActionDict;
1787 the_filterActionDict = 0;
1788 delete the_undoStack;
1790 delete the_popFilterMgr;
1791 the_popFilterMgr = 0;
1798 TDEConfig* config = KMKernel::config();
1799 TDEConfigGroupSaver saver(config,
"General");
1801 if (the_trashFolder) {
1803 the_trashFolder->close(
"kmkernel",
true);
1805 if (config->readBoolEntry(
"empty-trash-on-exit",
true))
1807 if ( the_trashFolder->count(
true ) > 0 )
1808 the_trashFolder->expunge();
1812 mICalIface->cleanup();
1814 TQValueList<TQGuardedPtr<KMFolder> > folders;
1815 TQStringList strList;
1817 the_folderMgr->createFolderList(&strList, &folders);
1818 for (
int i = 0; folders.at(i) != folders.end(); i++)
1820 folder = *folders.at(i);
1821 if (!folder || folder->isDir())
continue;
1822 folder->
close(
"kmkernel",
true);
1826 the_searchFolderMgr->createFolderList(&strList, &folders);
1827 for (
int i = 0; folders.at(i) != folders.end(); i++)
1829 folder = *folders.at(i);
1830 if (!folder || folder->isDir())
continue;
1831 folder->
close(
"kmkernel",
true);
1834 delete the_msgIndex;
1836 delete the_folderMgr;
1838 delete the_imapFolderMgr;
1839 the_imapFolderMgr = 0;
1840 delete the_dimapFolderMgr;
1841 the_dimapFolderMgr = 0;
1842 delete the_searchFolderMgr;
1843 the_searchFolderMgr = 0;
1844 delete mConfigureDialog;
1845 mConfigureDialog = 0;
1850 if ( RecentAddresses::exists() )
1851 RecentAddresses::self( config )->save( config );
1860 TQFileInfo fi( TQDir::home(),
"KMail" );
1861 if ( fi.exists() && fi.isDir() ) {
1862 dir = TQDir::homeDirPath() +
"/KMail";
1864 destinationDir = dir;
1868 if ( dir.isEmpty() ) {
1870 fi.setFile( TQDir::home(),
"Mail" );
1871 if ( fi.exists() && fi.isDir() &&
1872 TQFile::exists( TQDir::homeDirPath() +
"/Mail/.inbox.index" ) ) {
1875 dir = TQDir::homeDirPath() +
"/Mail";
1877 destinationDir = dir;
1882 if ( dir.isEmpty() ) {
1888 const TQString kmailName = kapp->aboutData()->programName();
1890 if ( TDEIO::NetAccess::exists( destinationDir,
true, 0 ) ) {
1893 msg = i18n(
"%1-%3 is the application name, %4-%7 are folder path",
1894 "<qt>The <i>%4</i> folder exists. " 1895 "%1 now uses the <i>%5</i> folder for " 1897 "%2 can move the contents of <i>%6<i> into this folder for " 1898 "you, though this may replace any existing files with " 1899 "the same name in <i>%7</i>.<p>" 1900 "<strong>Would you like %3 to move the mail " 1901 "files now?</strong></qt>" )
1902 .arg( kmailName, kmailName, kmailName )
1903 .arg( dir, destinationDir, dir, destinationDir );
1905 msg = i18n(
"%1-%3 is the application name, %4-%6 are folder path",
1906 "<qt>The <i>%4</i> folder exists. " 1907 "%1 now uses the <i>%5</i> folder for " 1908 "its messages. %2 can move the contents of <i>%6</i> into " 1909 "this folder for you.<p>" 1910 "<strong>Would you like %3 to move the mail " 1911 "files now?</strong></qt>" )
1912 .arg( kmailName, kmailName, kmailName )
1913 .arg( dir, destinationDir, dir );
1915 TQString title = i18n(
"Migrate Mail Files?" );
1916 TQString buttonText = i18n(
"Move" );
1918 if ( KMessageBox::questionYesNo( 0, msg, title, buttonText, i18n(
"Do Not Move") ) ==
1920 destinationDir = dir;
1924 if ( !TDEIO::NetAccess::move( dir, destinationDir ) ) {
1925 kdDebug(5006) << k_funcinfo <<
"Moving " << dir <<
" to " << destinationDir <<
" failed: " << TDEIO::NetAccess::lastErrorString() << endl;
1926 kdDebug(5006) << k_funcinfo <<
"Deleting " << destinationDir << endl;
1927 TDEIO::NetAccess::del( destinationDir, 0 );
1928 destinationDir = dir;
1937 void KMKernel::ungrabPtrKb(
void)
1939 if(!TDEMainWindow::memberList)
return;
1940 TQWidget* widg = TDEMainWindow::memberList->first();
1944 dpy = widg->x11Display();
1945 XUngrabKeyboard(dpy, CurrentTime);
1946 XUngrabPointer(dpy, CurrentTime);
1951 void KMKernel::kmailMsgHandler(TQtMsgType aType,
const char* aMsg)
1953 static int recurse=-1;
1961 kdDebug(5006) << aMsg << endl;
1966 kdDebug(5006) << kapp->caption() <<
" fatal error " 1968 KMessageBox::error(0, aMsg);
1978 if ( shuttingDown() )
1982 if ( !TDEMainWindow::memberList )
1985 for ( TQPtrListIterator<TDEMainWindow> it(*TDEMainWindow::memberList) ; it.current() != 0; ++it ) {
1986 if ( KMail::Composer * win = ::tqqt_cast<KMail::Composer*>( it.current() ) ) {
1987 win->autoSaveMessage();
1992 while ( win->isComposing() )
1993 tqApp->processEvents();
2000 void KMKernel::action(
bool mailto,
bool check,
const TQString &to,
2001 const TQString &cc,
const TQString &bcc,
2002 const TQString &subj,
const TQString &body,
2003 const KURL &messageFile,
2004 const KURL::List &attachURLs,
2005 const QCStringList &customHeaders)
2008 openComposer( to, cc, bcc, subj, body, 0, messageFile, attachURLs, customHeaders );
2010 openReader( check );
2017 void KMKernel::byteArrayToRemoteFile(
const TQByteArray &aData,
const KURL &aURL,
2021 TDEIO::Job *job = TDEIO::put(aURL, -1, overwrite,
false);
2022 putData pd; pd.url = aURL; pd.data = aData; pd.offset = 0;
2023 mPutJobs.insert(job, pd);
2024 connect(job, TQT_SIGNAL(dataReq(TDEIO::Job*,TQByteArray&)),
2025 TQT_SLOT(slotDataReq(TDEIO::Job*,TQByteArray&)));
2026 connect(job, TQT_SIGNAL(result(TDEIO::Job*)),
2027 TQT_SLOT(slotResult(TDEIO::Job*)));
2030 void KMKernel::slotDataReq(TDEIO::Job *job, TQByteArray &data)
2033 const int MAX_CHUNK_SIZE = 64*1024;
2034 TQMap<TDEIO::Job*, putData>::Iterator it = mPutJobs.find(job);
2035 assert(it != mPutJobs.end());
2036 int remainingBytes = (*it).data.size() - (*it).offset;
2037 if( remainingBytes > MAX_CHUNK_SIZE )
2040 data.duplicate( (*it).data.data() + (*it).offset, MAX_CHUNK_SIZE );
2041 (*it).offset += MAX_CHUNK_SIZE;
2048 data.duplicate( (*it).data.data() + (*it).offset, remainingBytes );
2049 (*it).data = TQByteArray();
2055 void KMKernel::slotResult(TDEIO::Job *job)
2057 TQMap<TDEIO::Job*, putData>::Iterator it = mPutJobs.find(job);
2058 assert(it != mPutJobs.end());
2061 if (job->error() == TDEIO::ERR_FILE_ALREADY_EXIST)
2063 if (KMessageBox::warningContinueCancel(0,
2064 i18n(
"File %1 exists.\nDo you want to replace it?")
2065 .arg((*it).url.prettyURL()), i18n(
"Save to File"), i18n(
"&Replace"))
2066 == KMessageBox::Continue)
2067 byteArrayToRemoteFile((*it).data, (*it).url,
true);
2069 else job->showErrorDialog();
2071 mPutJobs.remove(it);
2076 KMKernel::config()->sync();
2079 void KMKernel::slotShowConfigurationDialog()
2081 if( !mConfigureDialog ) {
2082 mConfigureDialog =
new ConfigureDialog( 0,
"configure",
false );
2083 connect( mConfigureDialog, TQT_SIGNAL( configChanged() ),
2084 this, TQT_SLOT( slotConfigChanged() ) );
2092 KMMainWin * win =
new KMMainWin;
2095 if( mConfigureDialog->isHidden() )
2097 getKMMainWidget()->headers()->writeConfig();
2098 mConfigureDialog->show();
2101 mConfigureDialog->raise();
2104 void KMKernel::slotConfigChanged()
2107 emit configChanged();
2114 return locateLocal(
"data",
"kmail/" );
2121 return !systemTrayApplets.isEmpty();
2124 bool KMKernel::registerSystemTrayApplet(
const KSystemTray* applet )
2126 if ( systemTrayApplets.findIndex( applet ) == -1 ) {
2127 systemTrayApplets.append( applet );
2134 bool KMKernel::unregisterSystemTrayApplet(
const KSystemTray* applet )
2136 TQValueList<const KSystemTray*>::iterator it =
2137 systemTrayApplets.find( applet );
2138 if ( it != systemTrayApplets.end() ) {
2139 systemTrayApplets.remove( it );
2146 void KMKernel::emergencyExit(
const TQString& reason )
2149 if ( reason.length() == 0 ) {
2150 mesg = i18n(
"KMail encountered a fatal error and will terminate now");
2152 mesg = i18n(
"KMail encountered a fatal error and will " 2153 "terminate now.\nThe error was:\n%1").arg( reason );
2156 kdWarning() << mesg << endl;
2157 KNotifyClient::userEvent( 0,
"<qt>"+mesg+
"</qt>", KNotifyClient::Messagebox, KNotifyClient::Error );
2168 if ( folder == the_outboxFolder )
2170 return folderIsDrafts( folder );
2176 if ( folder == the_draftsFolder )
2179 TQString idString = folder->
idString();
2180 if ( idString.isEmpty() )
2184 const KPIM::IdentityManager *im = identityManager();
2185 for ( KPIM::IdentityManager::ConstIterator it=im->begin(); it != im->end(); ++it )
2186 if ( (*it).drafts() == idString )
2191 bool KMKernel::folderIsTemplates(
const KMFolder *folder )
2194 if ( folder == the_templatesFolder )
2197 TQString idString = folder->
idString();
2198 if ( idString.isEmpty() )
2202 const KPIM::IdentityManager *im = identityManager();
2203 for ( KPIM::IdentityManager::ConstIterator it=im->begin(); it != im->end(); ++it )
2204 if ( (*it).templates() == idString )
2209 bool KMKernel::folderIsTrash(
KMFolder * folder)
2212 if (folder == the_trashFolder)
return true;
2213 TQStringList actList = acctMgr()->getAccounts();
2214 TQStringList::Iterator it( actList.begin() );
2215 for( ; it != actList.end() ; ++it ) {
2216 KMAccount* act = acctMgr()->findByName( *it );
2217 if ( act && ( act->trash() == folder->
idString() ) )
2226 if ( folder == the_sentFolder )
2229 TQString idString = folder->
idString();
2230 if ( idString.isEmpty() )
return false;
2233 const KPIM::IdentityManager * im = identityManager();
2234 for( KPIM::IdentityManager::ConstIterator it = im->begin(); it != im->end(); ++it )
2235 if ( (*it).fcc() == idString )
return true;
2240 if ( !mIdentityManager ) {
2241 kdDebug(5006) <<
"instantating KPIM::IdentityManager" << endl;
2242 mIdentityManager =
new KPIM::IdentityManager(
false,
this,
"mIdentityManager" );
2244 return mIdentityManager;
2247 KMMsgIndex *KMKernel::msgIndex()
2249 return the_msgIndex;
2254 if (TDEMainWindow::memberList) {
2255 TDEMainWindow *kmWin = 0;
2258 for (kmWin = TDEMainWindow::memberList->first(); kmWin;
2259 kmWin = TDEMainWindow::memberList->next())
2260 if (kmWin->isA(
"KMMainWin"))
2266 kmWin = TDEMainWindow::memberList->first();
2275 mWin =
new KMMainWin;
2285 TQString title = i18n(
"Empty Trash");
2286 TQString text = i18n(
"Are you sure you want to empty the trash folders of all accounts?");
2287 if (KMessageBox::warningContinueCancel(0, text, title,
2288 KStdGuiItem::cont(),
"confirm_empty_trash")
2289 != KMessageBox::Continue)
2294 for (KMAccount* acct = acctMgr()->first(); acct; acct = acctMgr()->next())
2296 KMFolder* trash = findFolderById(acct->trash());
2304 TDEConfig* KMKernel::config()
2307 if (!mySelf->mConfig)
2309 mySelf->mConfig = TDESharedConfig::openConfig(
"kmailrc" );
2311 KMail::checkConfigUpdates();
2313 return mySelf->mConfig;
2318 assert( mICalIface );
2322 void KMKernel::selectFolder( TQString folderPath )
2324 kdDebug(5006)<<
"Selecting a folder "<<folderPath<<endl;
2325 const TQString localPrefix =
"/Local";
2326 KMFolder *folder = kmkernel->folderMgr()->getFolderByURL( folderPath );
2327 if ( !folder && folderPath.startsWith( localPrefix ) )
2328 folder = the_folderMgr->getFolderByURL( folderPath.mid( localPrefix.length() ) );
2330 folder = kmkernel->imapFolderMgr()->getFolderByURL( folderPath );
2332 folder = kmkernel->dimapFolderMgr()->getFolderByURL( folderPath );
2335 KMMainWidget *widget = getKMMainWidget();
2340 KMFolderTree *tree = widget->folderTree();
2341 tree->doFolderSelected( tree->indexOfFolder( folder ) );
2342 tree->ensureItemVisible( tree->indexOfFolder( folder ) );
2348 TQWidgetList *l = kapp->topLevelWidgets();
2349 TQWidgetListIt it( *l );
2352 while ( ( wid = it.current() ) != 0 ) {
2354 TQObjectList *l2 = wid->topLevelWidget()->queryList(
"KMMainWidget" );
2355 if (l2 && l2->first()) {
2356 KMMainWidget* kmmw =
dynamic_cast<KMMainWidget *
>( l2->first() );
2368 void KMKernel::slotRunBackgroundTasks()
2372 TDEConfigGroup generalGroup( config(),
"General" );
2374 if ( generalGroup.readBoolEntry(
"auto-expiring",
true ) ) {
2375 the_folderMgr->expireAllFolders(
false );
2376 the_imapFolderMgr->expireAllFolders(
false );
2377 the_dimapFolderMgr->expireAllFolders(
false );
2381 if ( generalGroup.readBoolEntry(
"auto-compaction",
true ) ) {
2382 the_folderMgr->compactAllFolders(
false );
2384 the_dimapFolderMgr->compactAllFolders(
false );
2388 #ifdef DEBUG_SCHEDULER // for debugging, see jobscheduler.h 2389 mBackgroundTasksTimer->start( 60 * 1000,
true );
2391 mBackgroundTasksTimer->start( 4 * 60 * 60 * 1000,
true );
2398 the_folderMgr->expireAllFolders(
true );
2399 the_imapFolderMgr->expireAllFolders(
true );
2400 the_dimapFolderMgr->expireAllFolders(
true );
2405 the_folderMgr->compactAllFolders(
true );
2407 the_dimapFolderMgr->compactAllFolders(
true );
2412 KMFolder * folder = the_folderMgr->findIdString( idString );
2414 folder = the_imapFolderMgr->findIdString( idString );
2416 folder = the_dimapFolderMgr->findIdString( idString );
2418 folder = the_searchFolderMgr->findIdString( idString );
2424 return KIMProxy::instance( kapp->dcopClient() );
2429 mMailCheckAborted =
false;
2434 return mMailCheckAborted;
2439 mMailCheckAborted =
true;
2442 bool KMKernel::canQueryClose()
2444 if ( KMMainWidget::mainWidgetList() &&
2445 KMMainWidget::mainWidgetList()->count() > 1 )
2447 KMMainWidget *widget = getKMMainWidget();
2451 if ( !systray || GlobalSettings::closeDespiteSystemTray() )
2453 if ( systray->mode() == GlobalSettings::EnumSystemTrayPolicy::ShowAlways ) {
2454 systray->hideKMail();
2456 }
else if ( ( systray->mode() == GlobalSettings::EnumSystemTrayPolicy::ShowOnUnread ) && ( systray->hasUnreadMail() )) {
2458 systray->hideKMail();
2466 mTimeOfLastMessageCountChange = ::time( 0 );
2469 int KMKernel::timeOfLastMessageCountChange()
const 2471 return mTimeOfLastMessageCountChange;
2474 bool KMKernel::networkStateConnected()
2476 #ifdef __TDE_HAVE_TDEHWLIB 2477 if (mNetworkManager) {
2478 TDENetworkGlobalManagerFlags::TDENetworkGlobalManagerFlags networkStatus = mNetworkManager->backendStatus();
2479 if ((networkStatus & TDENetworkGlobalManagerFlags::Connected)
2480 || (networkStatus & TDENetworkGlobalManagerFlags::BackendUnavailable)
2481 || (networkStatus == TDENetworkGlobalManagerFlags::Unknown)
2499 void KMKernel::slotNetworkStateChanged(TDENetworkConnectionStatus::TDENetworkConnectionStatus, TDENetworkConnectionStatus::TDENetworkConnectionStatus, TQString)
2501 if (networkStateConnected()) {
2502 resumeNetworkJobs();
2510 static bool walletOpenFailed =
false;
2511 if ( mWallet && mWallet->isOpen() )
2514 if ( !Wallet::isEnabled() || walletOpenFailed )
2519 if ( tqApp->activeWindow() )
2520 window = tqApp->activeWindow()->winId();
2521 else if ( getKMMainWidget() )
2522 window = getKMMainWidget()->topLevelWidget()->winId();
2525 mWallet = Wallet::openWallet( Wallet::NetworkWallet(), window );
2528 walletOpenFailed =
true;
2532 if ( !mWallet->hasFolder(
"kmail" ) )
2533 mWallet->createFolder(
"kmail" );
2534 mWallet->setFolder(
"kmail" );
2541 TQValueList<TQGuardedPtr<KMFolder> > folders;
2542 folderMgr()->createFolderList(&names, &folders);
2543 imapFolderMgr()->createFolderList(&names, &folders);
2544 dimapFolderMgr()->createFolderList(&names, &folders);
2545 searchFolderMgr()->createFolderList(&names, &folders);
2550 KMFolder *KMKernel::currentFolder() {
2551 KMMainWidget *widget = getKMMainWidget();
2553 if ( widget && widget->folderTree() ) {
2554 folder = widget->folderTree()->currentFolder();
2561 KMail::MessageSender * KMKernel::msgSender() {
return the_msgSender; }
2563 #include "kmkernel.moc" void abortMailCheck()
Set the state of the abort requested variable to true, (to let the current jobs run, but stop when possible).
virtual TQString getFrom(TQ_UINT32 serialNumber)
DCOP-enabled for use in kaddressbook drop.
void getLocation(unsigned long key, KMFolder **retFolder, int *retIndex) const
Returns the folder the message represented by the serial number key is in and the index in that folde...
void stopNetworkJobs()
Stops all network related jobs and enter offline mode New network jobs cannot be started.
void setStatus(const KMMsgStatus status, int idx=-1)
Set status and mark dirty.
int dcopAddMessage(const TQString &foldername, const TQString &messagefile, const TQString &MsgStatusFlags=TQString())
A FolderStorage with an index for faster access to often used message properties. ...
Central point of coordination in KMail.
void initHeader(uint identity=0)
Initialize header fields.
KMFolder * findFolderById(const TQString &idString)
Find a folder by ID string in all folder managers.
RAII for KMFolder::open() / close().
TQValueList< TQGuardedPtr< KMFolder > > allFolders()
static KMKernel * self()
normal control stuff
const KMMsgBase * getMsgBase(int idx) const
Provides access to the basic message fields that are also stored in the index.
void setBody(const TQCString &aStr)
Set the message body.
static const KMMsgDict * instance()
Access the globally unique MessageDict.
bool folderIsDraftOrOutbox(const KMFolder *)
Returns true if the folder is either the outbox or one of the drafts-folders.
TQString from() const
Get or set the 'From' header field.
void setCharset(const TQCString &charset, DwEntity *entity=0)
Sets the charset of the message or a subpart of the message.
virtual bool showMail(TQ_UINT32 serialNumber, TQString messageId)
Shows the specified message in a separate message window.
int openComposer(const TQString &to, const TQString &cc, const TQString &bcc, const TQString &subject, const TQString &body, int hidden, const KURL &messageFile, const KURL::List &attachURLs, const QCStringList &customHeaders)
returns id of composer if more are opened
void enableMailCheck()
Set the state of the abort requested variable to false, i.e.
void setHeaderField(const TQCString &name, const TQString &value, HeaderFieldType type=Unstructured, bool prepend=false)
Set the header field with the given name to the given value.
bool mailCheckAborted() const
Returns true IFF the user has requested that the current mail checks should be aborted.
void slotEmptyTrash()
empty all the trash bins
void setMsgSerNum(unsigned long newMsgSerNum=0)
Sets the message serial number.
The TemplateParser transforms a message with a given template.
void dcopResetAddMessage()
Clears the list of added message ids which is used to filter out duplicates.
Dictionary that contains a list of all registered filter actions with their creation functions...
static TQString localDataPath()
Returns the full path of the user's local data directory for KMail.
TDEWallet::Wallet * wallet()
Open KDE wallet and set it to kmail folder.
void resumeNetworkJobs()
Resumes all network related jobs and enter online mode New network jobs can be started.
int sendCertificate(const TQString &to, const TQByteArray &certData)
Send a certificate request to the CA specified in to.
TQString dateStr() const
Get or set the 'Date' header field.
KMFolderDir * createChildFolder()
Create a child folder directory and associates it with this folder.
void setReadyToShow(bool v)
Set if the message is ready to be shown.
void messageCountChanged()
Called by the folder tree if the count of unread/total messages changed.
void compactAllFolders()
Compact all folders, used for the gui action (and from DCOP)
KMail list that manages the contents of one directory that may contain folders and/or other directori...
bool transferMail(TQString &destinationDir)
Returns true if the transfer was successful, otherwise false.
void checkMail()
dcop callable stuff
int expunge()
Delete entire folder.
void remove()
Removes the folder physically from disk and empties the contents of the folder in memory...
static bool isOffline()
Checks if the current network state is online or offline.
void slotRequestConfigSync()
Call this slot instead of directly TDEConfig::sync() to minimize the overall config writes...
int find(const KMMsgBase *msg) const
Returns the index of the given message or -1 if not found.
TDEMainWindow * mainWin()
returns a reference to the first Mainwin or a temporary Mainwin
TQString subject() const
Get or set the 'Subject' header field.
TQString idString() const
Returns a string that can be used to identify this folder.
KMSystemTray extends KSystemTray and handles system tray notification for KMail.
static bool askToGoOnline()
A static helper function that asks the user if they want to go online.
The implementation of the interface.
KMMessage * getMsg(int idx)
Read message at given index.
bool haveSystemTrayApplet()
Returns true if we have a system tray applet.
void close(const char *owner, bool force=false)
Close folder.
bool isOpened() const
Test if folder is opened.
The account manager is responsible for creating accounts of various types via the factory method crea...
::KIMProxy * imProxy()
Get a reference to KMail's KIMProxy instance.
static void readConfig()
Reads config settings from group "KMMessage" and sets all internal variables (e.g.
virtual void resumeBackgroundJobs()
Resumes all background jobs and allows new jobs to be started.
static TQStringList transportNames()
Returns the list for transport names.
bool handleCommandLine(bool noArgsOpensReader)
Reimplemented from KMailIface.
void dumpDeadLetters()
Save contents of all open composer widnows to ~/dead.letter.
KMFolderType folderType() const
Returns the type of this folder.
bool folderIsSentMailFolder(const KMFolder *)
Returns true if the folder is one of the sent-mail folders.
DCOPRef newMessage(const TQString &to, const TQString &cc, const TQString &bcc, bool hidden, bool useFolderId, const KURL &messageFile, const KURL &attachURL)
DCOP call used by the Kontact plugin to create a new message.
int open(const char *owner)
Open folder for access.
KPIM::IdentityManager * identityManager()
return the pointer to the identity manager
KMMsgInfo * unGetMsg(int idx)
Replace KMMessage with KMMsgInfo and delete KMMessage.
virtual IndexStatus indexStatus()=0
Tests whether the contents of this folder is newer than the index.
The unique JobScheduler instance (owned by kmkernel) implements "background processing" of folder ope...
void expireAllFoldersNow()
Expire all folders, used for the gui action.
void setDefaultTransport(const TQString &transport)
DCOP call used to set the default transport.
virtual void pauseBackgroundJobs()
Pauses all background jobs and does not allow new background jobs to be started.
int dcopAddMessage_fastImport(const TQString &foldername, const TQString &messagefile, const TQString &MsgStatusFlags=TQString())
add messages without rejecting duplicates
KMMainWidget * getKMMainWidget()
Get first mainwidget.