1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134
|
/*
* Copyright (c) 1996-1998 Stefan Taferner <taferner@kde.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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 "filteractionsetidentity.h"
#include "messagecore/utils/stringutil.h"
#include "kernel/mailkernel.h"
#include "dialog/filteractionmissingargumentdialog.h"
#include <KDE/KPIMIdentities/Identity>
#include <KDE/KPIMIdentities/IdentityCombo>
#include <KDE/KPIMIdentities/IdentityManager>
#include <KDE/KLocale>
#include <QPointer>
using namespace MailCommon;
FilterAction* FilterActionSetIdentity::newAction()
{
return new FilterActionSetIdentity;
}
FilterActionSetIdentity::FilterActionSetIdentity( QObject *parent )
: FilterActionWithUOID( QLatin1String("set identity"), i18n( "Set Identity To" ), parent )
{
mParameter = KernelIf->identityManager()->defaultIdentity().uoid();
}
bool FilterActionSetIdentity::argsFromStringInteractive( const QString &argsStr, const QString &filterName )
{
bool needUpdate = false;
argsFromString( argsStr );
if ( KernelIf->identityManager()->identityForUoid( mParameter ).isNull() )
{
QPointer<FilterActionMissingIdentityDialog> dlg = new FilterActionMissingIdentityDialog( filterName );
if ( dlg->exec() ) {
mParameter = dlg->selectedIdentity();
needUpdate = true;
}
else
mParameter = -1;
delete dlg;
}
return needUpdate;
}
FilterAction::ReturnCode FilterActionSetIdentity::process(ItemContext &context , bool applyOnOutbound) const
{
const KPIMIdentities::Identity & ident =
KernelIf->identityManager()->identityForUoid( mParameter );
if ( ident.isNull() )
return ErrorButGoOn;
const KMime::Message::Ptr msg = context.item().payload<KMime::Message::Ptr>();
const uint currentId = msg->headerByType( "X-KMail-Identity" ) ? msg->headerByType( "X-KMail-Identity" )->asUnicodeString().trimmed().toUInt() : 0;
if (currentId != mParameter) {
KMime::Headers::Generic *header = new KMime::Headers::Generic( "X-KMail-Identity", msg.get(), QString::number( mParameter ), "utf-8" );
if (applyOnOutbound) {
msg->from()->fromUnicodeString( ident.fullEmailAddr(), "utf-8" );
if (!ident.bcc().isEmpty()) {
const KMime::Types::Mailbox::List mailboxes = MessageCore::StringUtil::mailboxListFromUnicodeString( ident.bcc() );
foreach ( const KMime::Types::Mailbox &mailbox, mailboxes )
msg->bcc()->addAddress( mailbox );
}
}
msg->setHeader( header );
msg->assemble();
context.setNeedsPayloadStore();
}
return GoOn;
}
SearchRule::RequiredPart FilterActionSetIdentity::requiredPart() const
{
return SearchRule::CompleteMessage;
}
QWidget* FilterActionSetIdentity::createParamWidget( QWidget *parent ) const
{
KPIMIdentities::IdentityCombo *comboBox = new KPIMIdentities::IdentityCombo( KernelIf->identityManager(), parent );
comboBox->setCurrentIdentity( mParameter );
connect( comboBox, SIGNAL(currentIndexChanged(int)), this, SIGNAL(filterActionModified()) );
return comboBox;
}
void FilterActionSetIdentity::applyParamWidgetValue( QWidget *paramWidget )
{
const KPIMIdentities::IdentityCombo *comboBox = dynamic_cast<KPIMIdentities::IdentityCombo*>( paramWidget );
Q_ASSERT( comboBox );
mParameter = comboBox->currentIdentity();
}
void FilterActionSetIdentity::clearParamWidget( QWidget *paramWidget ) const
{
KPIMIdentities::IdentityCombo *comboBox = dynamic_cast<KPIMIdentities::IdentityCombo*>( paramWidget );
Q_ASSERT( comboBox );
comboBox->setCurrentIndex( 0 );
}
void FilterActionSetIdentity::setParamWidgetValue( QWidget *paramWidget ) const
{
KPIMIdentities::IdentityCombo *comboBox = dynamic_cast<KPIMIdentities::IdentityCombo*>( paramWidget );
Q_ASSERT( comboBox );
comboBox->setCurrentIdentity( mParameter );
}
|