/* Copyright (c) 2012-2013 Montel Laurent This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License, version 2, as published by the Free Software Foundation. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include "thunderbirdsettings.h" #include #include "mailcommon/util/mailutil.h" #include "importwizardutil.h" #include #include #include #include #include #include #include #include ThunderbirdSettings::ThunderbirdSettings( const QString& filename, ImportWizard *parent ) :AbstractSettings( parent ) { QFile file(filename); if ( !file.open( QIODevice::ReadOnly ) ) { kDebug()<<" We can't open file"<& settings, const QString & argument, const QString &accountName ) { bool found = false; if ( mHashConfig.contains( accountName + QLatin1String( ".authMethod" ) ) ) { const int authMethod = mHashConfig.value( accountName + QLatin1String( ".authMethod" ) ).toInt(&found); if ( found ) { switch( authMethod ) { case 0: break; case 4: //Encrypted password ??? settings.insert( argument, MailTransport::Transport::EnumAuthenticationType::LOGIN ); //???? kDebug()<<" authmethod == encrypt password"; break; case 5: //GSSAPI settings.insert( argument, MailTransport::Transport::EnumAuthenticationType::GSSAPI ); break; case 6: //NTLM settings.insert( argument, MailTransport::Transport::EnumAuthenticationType::NTLM ); break; case 7: //TLS kDebug()<<" authmethod method == TLS"; //???? break; default: kDebug()<<" ThunderbirdSettings::addAuth unknown :"< settings; settings.insert(QLatin1String("ImapServer"),host); settings.insert(QLatin1String("UserName"),userName); const int port = mHashConfig.value( accountName + QLatin1String( ".port" ) ).toInt( &found); if ( found ) { settings.insert( QLatin1String( "ImapPort" ), port ); } addAuth( settings, QLatin1String( "Authentication" ), accountName ); const QString offline = accountName + QLatin1String( ".offline_download" ); if ( mHashConfig.contains( offline ) ) { const bool offlineStatus = mHashConfig.value( offline ).toBool(); if ( offlineStatus ) { settings.insert( QLatin1String( "DisconnectedModeEnabled" ), offlineStatus ); } } else { //default value == true settings.insert( QLatin1String( "DisconnectedModeEnabled" ), true ); } found = false; const int socketType = mHashConfig.value( accountName + QLatin1String( ".socketType" ) ).toInt( &found); if (found) { switch(socketType) { case 0: //None settings.insert( QLatin1String( "Safety" ), QLatin1String("None") ); break; case 2: //STARTTLS settings.insert( QLatin1String( "Safety" ), QLatin1String("STARTTLS") ); break; case 3: //SSL/TLS settings.insert( QLatin1String( "Safety" ), QLatin1String("SSL") ); break; default: kDebug()<<" socketType "< settings; settings.insert( QLatin1String( "Host" ), host ); settings.insert( QLatin1String( "Login" ), userName ); const bool leaveOnServer = mHashConfig.value( accountName + QLatin1String( ".leave_on_server")).toBool(); if (leaveOnServer) { settings.insert(QLatin1String("LeaveOnServer"),leaveOnServer); } found = false; const int numberDayToLeave = mHashConfig.value( accountName + QLatin1String( ".num_days_to_leave_on_server")).toInt(&found); if ( found ) { settings.insert(QLatin1String("LeaveOnServerDays"),numberDayToLeave); } found = false; const int port = mHashConfig.value( accountName + QLatin1String( ".port" ) ).toInt( &found); if ( found ) { settings.insert( QLatin1String( "Port" ), port ); } found = false; const int socketType = mHashConfig.value( accountName + QLatin1String( ".socketType" ) ).toInt( &found); if (found) { switch(socketType) { case 0: //None //nothing break; case 2: //STARTTLS settings.insert( QLatin1String( "UseTLS" ), true ); break; case 3: //SSL/TLS settings.insert( QLatin1String( "UseSSL" ), true ); break; default: kDebug()<<" socketType "<setName(name); const QString hostName = mHashConfig.value( smtpName + QLatin1String( ".hostname" ) ).toString(); mt->setHost( hostName ); const int port = mHashConfig.value( smtpName + QLatin1String( ".port" ) ).toInt(); if ( port > 0 ) mt->setPort( port ); const int authMethod = mHashConfig.value( smtpName + QLatin1String( ".authMethod" ) ).toInt(); switch(authMethod) { case 0: break; case 1: //No authentication mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::PLAIN); //???? break; case 3: //Unencrypted password mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::CLEAR); //??? break; case 4: //crypted password mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::LOGIN); //??? break; case 5: //GSSAPI mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::GSSAPI); break; case 6: //NTLM mt->setAuthenticationType(MailTransport::Transport::EnumAuthenticationType::NTLM); break; default: kDebug()<<" authMethod unknown :"<setEncryption( MailTransport::Transport::EnumEncryption::None ); break; case 2: mt->setEncryption( MailTransport::Transport::EnumEncryption::TLS ); break; case 3: mt->setEncryption( MailTransport::Transport::EnumEncryption::SSL ); break; default: kDebug()<<" trySsl unknown :"<setUserName( userName ); if (authMethod > 1) { mt->setRequiresAuthentication( true ); } } storeTransport( mt, ( smtp == defaultSmtp ) ); mHashSmtp.insert( smtp, QString::number( mt->id() ) ); } } QString convertThunderbirdPath(const QString& path) { QString newPath; KUrl url(path); newPath = url.path(); newPath.remove(0,1); return MailCommon::Util::convertFolderPathToCollectionStr(newPath); } void ThunderbirdSettings::readIdentity( const QString& account ) { const QString identity = QString::fromLatin1( "mail.identity.%1" ).arg( account ); QString fullName = mHashConfig.value( identity + QLatin1String( ".fullName" ) ).toString(); KPIMIdentities::Identity* newIdentity = createIdentity(fullName); const QString smtpServer = mHashConfig.value( identity + QLatin1String( ".smtpServer" ) ).toString(); if (!smtpServer.isEmpty() && mHashSmtp.contains(smtpServer)) { newIdentity->setTransport(mHashSmtp.value(smtpServer)); } const QString userEmail = mHashConfig.value( identity + QLatin1String( ".useremail" ) ).toString(); newIdentity->setPrimaryEmailAddress(userEmail); newIdentity->setFullName( fullName ); newIdentity->setIdentityName( fullName ); const QString organization = mHashConfig.value(identity + QLatin1String(".organization")).toString(); newIdentity->setOrganization(organization); bool doBcc = mHashConfig.value(identity + QLatin1String(".doBcc")).toBool(); if (doBcc) { const QString bcc = mHashConfig.value(identity + QLatin1String(".doBccList")).toString(); newIdentity->setBcc( bcc ); } bool doCc = mHashConfig.value(identity + QLatin1String(".doCc")).toBool(); if (doCc) { const QString cc = mHashConfig.value(identity + QLatin1String(".doCcList")).toString(); newIdentity->setCc( cc ); } const QString replyTo = mHashConfig.value(identity + QLatin1String( ".reply_to")).toString(); newIdentity->setReplyToAddr( replyTo ); KPIMIdentities::Signature signature; const bool signatureHtml = mHashConfig.value(identity + QLatin1String( ".htmlSigFormat" )).toBool(); if (signatureHtml) { signature.setInlinedHtml( true ); } const bool attachSignature = mHashConfig.value(identity + QLatin1String( ".attach_signature" )).toBool(); if ( attachSignature ) { const QString fileSignature = mHashConfig.value(identity + QLatin1String( ".sig_file")).toString(); signature.setType( KPIMIdentities::Signature::FromFile ); signature.setUrl( fileSignature,false ); } else { const QString textSignature = mHashConfig.value(identity + QLatin1String( ".htmlSigText" ) ).toString(); signature.setType( KPIMIdentities::Signature::Inlined ); signature.setText( textSignature ); } if ( mHashConfig.contains( identity + QLatin1String( ".drafts_folder_picker_mode" ) ) ) { const int useSpecificDraftFolder = mHashConfig.value( identity + QLatin1String( ".drafts_folder_picker_mode" ) ).toInt(); if ( useSpecificDraftFolder == 1 ) { const QString draftFolder = convertThunderbirdPath( mHashConfig.value( identity + QLatin1String( ".draft_folder" ) ).toString() ); newIdentity->setDrafts( draftFolder ); } } if ( mHashConfig.contains( identity + QLatin1String( ".fcc" ) ) ) { const bool fccEnabled = mHashConfig.value(identity + QLatin1String( ".fcc" )).toBool(); newIdentity->setDisabledFcc( !fccEnabled ); } //fcc_reply_follows_parent not implemented in kmail //fcc_folder_picker_mode is just a flag for thunderbird. Not necessary during import. //if ( mHashConfig.contains( identity + QLatin1String( ".fcc_folder_picker_mode" ) ) ) { if (mHashConfig.contains( identity + QLatin1String( ".fcc_folder" ) )) { const QString fccFolder = convertThunderbirdPath( mHashConfig.value( identity + QLatin1String( ".fcc_folder" ) ).toString() ); newIdentity->setFcc( fccFolder ); } } //if ( mHashConfig.contains( identity + QLatin1String( ".tmpl_folder_picker_mode" ) ) ) { if (mHashConfig.contains( identity + QLatin1String( ".stationery_folder" ) )) { const QString templateFolder = convertThunderbirdPath( mHashConfig.value( identity + QLatin1String( ".stationery_folder" ) ).toString() ); newIdentity->setTemplates( templateFolder ); } } const QString attachVcardStr( identity + QLatin1String( ".attach_vcard" ) ); if ( mHashConfig.contains( attachVcardStr ) ) { const bool attachVcard = mHashConfig.value( attachVcardStr ).toBool(); newIdentity->setAttachVcard(attachVcard); } const QString attachVcardContentStr( identity + QLatin1String( ".escapedVCard" ) ); if ( mHashConfig.contains( attachVcardContentStr ) ) { const QString str = mHashConfig.value( attachVcardContentStr ).toString(); QByteArray vcard = QByteArray::fromPercentEncoding ( str.toLocal8Bit() ); KABC::VCardConverter converter; KABC::Addressee addr = converter.parseVCard( vcard ); const QString filename = KStandardDirs::locateLocal("appdata",newIdentity->identityName() + QLatin1String(".vcf")); QFile file(filename); if ( file.open( QIODevice::WriteOnly |QIODevice::Text ) ) { const QByteArray data = converter.exportVCard( addr, KABC::VCardConverter::v3_0 ); file.write( data ); file.flush(); file.close(); newIdentity->setVCardFile(filename); } } const QString signMailStr( identity + QLatin1String( ".sign_mail" ) ); if ( mHashConfig.contains( signMailStr ) ) { const bool signMail = mHashConfig.value(signMailStr).toBool(); newIdentity->setPgpAutoSign(signMail); } const QString composeHtmlStr( identity + QLatin1String( ".compose_html" ) ); //TODO: implement it in kmail newIdentity->setSignature( signature ); storeIdentity(newIdentity); } void ThunderbirdSettings::insertIntoMap( const QString& line ) { QString newLine = line; newLine.remove( QLatin1String( "user_pref(\"" ) ); newLine.remove( QLatin1String( ");" ) ); const int pos = newLine.indexOf( QLatin1Char( ',' ) ); QString key = newLine.left( pos ); key.remove( key.length() -1, 1 ); QString valueStr = newLine.right( newLine.length() - pos -2); if ( valueStr.at( 0 ) == QLatin1Char( '"' ) ) { valueStr.remove( 0, 1 ); const int pos(valueStr.length()-1); if ( valueStr.at( pos ) == QLatin1Char( '"' ) ) valueStr.remove( pos, 1 ); //Store as String mHashConfig.insert( key, valueStr ); } else { if ( valueStr == QLatin1String( "true" ) ) { mHashConfig.insert( key, true ); } else if ( valueStr == QLatin1String( "false" ) ) { mHashConfig.insert( key, false ); } else { //Store as integer const int value = valueStr.toInt(); mHashConfig.insert( key, value ); } } if (key.contains(QLatin1String("ldap_")) && key.endsWith(QLatin1String(".description"))) { QString ldapAccountName = key; mLdapAccountList.append(ldapAccountName.remove(QLatin1String(".description"))); } if (key.contains(QLatin1String("mailnews.tags.")) && (key.endsWith(QLatin1String(".color")) || key.endsWith(QLatin1String(".tag")))) { QString name = key; name.remove(QLatin1String("mailnews.tags.")); name.remove(QLatin1String(".color")); name.remove(QLatin1String(".tag")); tagStruct tag; if (mHashTag.contains(name)) { tag = mHashTag.value(name); mHashTag.remove(name); } if (key.endsWith(QLatin1String(".color"))) { tag.color = QColor(mHashConfig.value(key).toString()); } else { tag.name = mHashConfig.value(key).toString(); } mHashTag.insert(name,tag); kDebug()<<" tag :"<