11 #include <libkdepim/kfileio.h>
12 #include <libkdepim/collectingprocess.h>
16 #include <kmessagebox.h>
20 #include <tqfileinfo.h>
22 #include <sys/types.h>
46 mType( isExecutable ? FromCommand : FromFile )
51 if ( mType != other.mType )
return false;
53 case Inlined:
return mText == other.mText;
55 case FromCommand:
return mUrl == other.mUrl;
57 case Disabled:
return true;
71 return textFromFile( ok );
73 return textFromCommand( ok );
75 kdFatal( 5006 ) <<
"Signature::type() returned unknown value!" << endl;
79 TQString Signature::textFromCommand(
bool * ok )
const
81 assert( mType == FromCommand );
84 if ( mUrl.isEmpty() ) {
90 CollectingProcess proc;
91 proc.setUseShell(
true);
96 if ( !proc.start( KProcess::Block, KProcess::Stdout ) )
99 rc = ( proc.normalExit() ) ? proc.exitStatus() : -1 ;
103 if ( ok ) *ok =
false;
104 TQString wmsg = i18n(
"<qt>Failed to execute signature script<br><b>%1</b>:<br>%2</qt>")
105 .arg( mUrl ).arg( strerror(rc) );
106 KMessageBox::error(0, wmsg);
111 if ( ok ) *ok =
true;
114 TQByteArray output = proc.collectedStdout();
117 return TQString::fromLocal8Bit( output.data(), output.size() );
120 TQString Signature::textFromFile(
bool * ok )
const
122 assert( mType == FromFile );
125 if ( !KURL(mUrl).isLocalFile() && !(TQFileInfo(mUrl).isRelative()
126 && TQFileInfo(mUrl).exists()) ) {
127 kdDebug( 5006 ) <<
"Signature::textFromFile: non-local URLs are unsupported" << endl;
128 if ( ok ) *ok =
false;
131 if ( ok ) *ok =
true;
133 return TQString::fromLocal8Bit( kFileToString( mUrl,
false ) );
138 bool internalOK =
false;
139 TQString signature =
rawText( &internalOK );
141 if ( ok ) *ok =
false;
144 if ( ok ) *ok =
true;
145 if ( signature.isEmpty() )
return signature;
146 if ( signature.startsWith( TQString::fromLatin1(
"-- \n") ) )
148 return TQString::fromLatin1(
"\n") += signature;
149 else if ( signature.find( TQString::fromLatin1(
"\n-- \n") ) != -1 )
155 return TQString::fromLatin1(
"\n-- \n") + signature;
162 mType = isExecutable ? FromCommand : FromFile ;
166 static const char sigTypeKey[] =
"Signature Type";
167 static const char sigTypeInlineValue[] =
"inline";
168 static const char sigTypeFileValue[] =
"file";
169 static const char sigTypeCommandValue[] =
"command";
170 static const char sigTypeDisabledValue[] =
"disabled";
171 static const char sigTextKey[] =
"Inline Signature";
172 static const char sigFileKey[] =
"Signature File";
173 static const char sigCommandKey[] =
"Signature Command";
175 void Signature::readConfig(
const KConfigBase * config )
177 TQString sigType = config->readEntry( sigTypeKey );
178 if ( sigType == sigTypeInlineValue ) {
180 }
else if ( sigType == sigTypeFileValue ) {
182 mUrl = config->readPathEntry( sigFileKey );
183 }
else if ( sigType == sigTypeCommandValue ) {
185 mUrl = config->readPathEntry( sigCommandKey );
189 mText = config->readEntry( sigTextKey );
192 void Signature::writeConfig( KConfigBase * config )
const
196 config->writeEntry( sigTypeKey, sigTypeInlineValue );
199 config->writeEntry( sigTypeKey, sigTypeFileValue );
200 config->writePathEntry( sigFileKey, mUrl );
203 config->writeEntry( sigTypeKey, sigTypeCommandValue );
204 config->writePathEntry( sigCommandKey, mUrl );
207 config->writeEntry( sigTypeKey, sigTypeDisabledValue );
210 config->writeEntry( sigTextKey, mText );
213 TQDataStream & KPIM::operator<<( TQDataStream & stream,
const KPIM::Signature & sig ) {
214 return stream << static_cast<TQ_UINT8>(sig.mType)
219 TQDataStream & KPIM::operator>>( TQDataStream & stream,
KPIM::Signature & sig ) {
234 return *identityNull;
237 bool Identity::isNull()
const {
238 return mIdentity.isEmpty() && mFullName.isEmpty() && mEmailAddr.isEmpty() &&
239 mEmailAliases.empty() &&
240 mOrganization.isEmpty() && mReplyToAddr.isEmpty() && mBcc.isEmpty() &&
241 mVCardFile.isEmpty() &&
242 mFcc.isEmpty() && mDrafts.isEmpty() && mTemplates.isEmpty() &&
243 mPGPEncryptionKey.isEmpty() && mPGPSigningKey.isEmpty() &&
244 mSMIMEEncryptionKey.isEmpty() && mSMIMESigningKey.isEmpty() &&
245 mTransport.isEmpty() && mDictionary.isEmpty() &&
246 mPreferredCryptoMessageFormat == Kleo::AutoFormat &&
247 mSignature.
type() == Signature::Disabled &&
252 bool same = mUoid == other.mUoid &&
253 mIdentity == other.mIdentity && mFullName == other.mFullName &&
254 mEmailAddr == other.mEmailAddr && mOrganization == other.mOrganization &&
255 mEmailAliases == other.mEmailAliases &&
256 mReplyToAddr == other.mReplyToAddr && mBcc == other.mBcc &&
257 mVCardFile == other.mVCardFile &&
258 mFcc == other.mFcc &&
259 mPGPEncryptionKey == other.mPGPEncryptionKey &&
260 mPGPSigningKey == other.mPGPSigningKey &&
261 mSMIMEEncryptionKey == other.mSMIMEEncryptionKey &&
262 mSMIMESigningKey == other.mSMIMESigningKey &&
263 mPreferredCryptoMessageFormat == other.mPreferredCryptoMessageFormat &&
264 mDrafts == other.mDrafts && mTemplates == other.mTemplates &&
265 mTransport == other.mTransport &&
266 mDictionary == other.mDictionary && mSignature == other.mSignature &&
267 mXFace == other.mXFace && mXFaceEnabled == other.mXFaceEnabled;
272 if ( mUoid != other.mUoid ) kdDebug() <<
"mUoid differs : " << mUoid <<
" != " << other.mUoid << endl;
273 if ( mIdentity != other.mIdentity ) kdDebug() <<
"mIdentity differs : " << mIdentity <<
" != " << other.mIdentity << endl;
274 if ( mFullName != other.mFullName ) kdDebug() <<
"mFullName differs : " << mFullName <<
" != " << other.mFullName << endl;
275 if ( mEmailAddr != other.mEmailAddr ) kdDebug() <<
"mEmailAddr differs : " << mEmailAddr <<
" != " << other.mEmailAddr << endl;
276 if ( mEmailAliases != other.mEmailAliases ) kdDebug() <<
"mEmailAliases differs : " << mEmailAliases.join(
";") <<
" != " << other.mEmailAliases.join(
";") << endl;
277 if ( mOrganization != other.mOrganization ) kdDebug() <<
"mOrganization differs : " << mOrganization <<
" != " << other.mOrganization << endl;
278 if ( mReplyToAddr != other.mReplyToAddr ) kdDebug() <<
"mReplyToAddr differs : " << mReplyToAddr <<
" != " << other.mReplyToAddr << endl;
279 if ( mBcc != other.mBcc ) kdDebug() <<
"mBcc differs : " << mBcc <<
" != " << other.mBcc << endl;
280 if ( mVCardFile != other.mVCardFile ) kdDebug() <<
"mVCardFile differs : " << mVCardFile <<
" != " << other.mVCardFile << endl;
281 if ( mFcc != other.mFcc ) kdDebug() <<
"mFcc differs : " << mFcc <<
" != " << other.mFcc << endl;
282 if ( mPGPEncryptionKey != other.mPGPEncryptionKey ) kdDebug() <<
"mPGPEncryptionKey differs : " << mPGPEncryptionKey <<
" != " << other.mPGPEncryptionKey << endl;
283 if ( mPGPSigningKey != other.mPGPSigningKey ) kdDebug() <<
"mPGPSigningKey differs : " << mPGPSigningKey <<
" != " << other.mPGPSigningKey << endl;
284 if ( mSMIMEEncryptionKey != other.mSMIMEEncryptionKey ) kdDebug() <<
"mSMIMEEncryptionKey differs : '" << mSMIMEEncryptionKey <<
"' != '" << other.mSMIMEEncryptionKey <<
"'" << endl;
285 if ( mSMIMESigningKey != other.mSMIMESigningKey ) kdDebug() <<
"mSMIMESigningKey differs : " << mSMIMESigningKey <<
" != " << other.mSMIMESigningKey << endl;
286 if ( mPreferredCryptoMessageFormat != other.mPreferredCryptoMessageFormat ) kdDebug() <<
"mPreferredCryptoMessageFormat differs : " << mPreferredCryptoMessageFormat <<
" != " << other.mPreferredCryptoMessageFormat << endl;
287 if ( mDrafts != other.mDrafts ) kdDebug() <<
"mDrafts differs : " << mDrafts <<
" != " << other.mDrafts << endl;
288 if ( mTemplates != other.mTemplates ) kdDebug() <<
"mTemplates differs : " << mTemplates <<
" != " << other.mTemplates << endl;
289 if ( mTransport != other.mTransport ) kdDebug() <<
"mTransport differs : " << mTransport <<
" != " << other.mTransport << endl;
290 if ( mDictionary != other.mDictionary ) kdDebug() <<
"mDictionary differs : " << mDictionary <<
" != " << other.mDictionary << endl;
291 if ( ! ( mSignature == other.mSignature ) ) kdDebug() <<
"mSignature differs" << endl;
297 const TQString & emailAddr,
const TQString & organization,
298 const TQString & replyToAddr )
299 : mUoid( 0 ), mIdentity( id ), mFullName( fullName ),
300 mEmailAddr( emailAddr ), mOrganization( organization ),
301 mReplyToAddr( replyToAddr ),
304 mBcc(
"" ), mVCardFile(
"" ), mPGPEncryptionKey(
"" ), mPGPSigningKey(
"" ),
305 mSMIMEEncryptionKey(
"" ), mSMIMESigningKey(
"" ), mFcc(
"" ),
306 mDrafts(
"" ), mTemplates(
"" ), mTransport(
"" ),
308 mXFace(
"" ), mXFaceEnabled( false ),
310 mPreferredCryptoMessageFormat( Kleo::AutoFormat )
321 mUoid = config->readUnsignedNumEntry(
"uoid",0);
323 mIdentity = config->readEntry(
"Identity");
324 mFullName = config->readEntry(
"Name");
325 mEmailAddr = config->readEntry(
"Email Address");
326 mEmailAliases = config->readListEntry(
"Email Aliases");
327 mVCardFile = config->readPathEntry(
"VCardFile");
328 mOrganization = config->readEntry(
"Organization");
329 mPGPSigningKey = config->readEntry(
"PGP Signing Key").latin1();
330 mPGPEncryptionKey = config->readEntry(
"PGP Encryption Key").latin1();
331 mSMIMESigningKey = config->readEntry(
"SMIME Signing Key").latin1();
332 mSMIMEEncryptionKey = config->readEntry(
"SMIME Encryption Key").latin1();
333 mPreferredCryptoMessageFormat = Kleo::stringToCryptoMessageFormat( config->readEntry(
"Preferred Crypto Message Format",
"none" ) );
334 mReplyToAddr = config->readEntry(
"Reply-To Address" );
335 mBcc = config->readEntry(
"Bcc" );
336 mFcc = config->readEntry(
"Fcc",
"sent-mail" );
339 mDrafts = config->readEntry(
"Drafts",
"drafts" );
340 if( mDrafts.isEmpty() )
342 mTemplates = config->readEntry(
"Templates",
"templates" );
343 if( mTemplates.isEmpty() )
344 mTemplates =
"templates";
345 mTransport = config->readEntry(
"Transport" );
346 mDictionary = config->readEntry(
"Dictionary" );
347 mXFace = config->readEntry(
"X-Face" );
348 mXFaceEnabled = config->readBoolEntry(
"X-FaceEnabled",
false );
350 mSignature.readConfig( config );
351 kdDebug(5006) <<
"Identity::readConfig(): UOID = " << mUoid
352 <<
" for identity named \"" << mIdentity <<
"\"" << endl;
358 config->writeEntry(
"uoid", mUoid);
360 config->writeEntry(
"Identity", mIdentity);
361 config->writeEntry(
"Name", mFullName);
362 config->writeEntry(
"Organization", mOrganization);
363 config->writeEntry(
"PGP Signing Key", mPGPSigningKey.data());
364 config->writeEntry(
"PGP Encryption Key", mPGPEncryptionKey.data());
365 config->writeEntry(
"SMIME Signing Key", mSMIMESigningKey.data());
366 config->writeEntry(
"SMIME Encryption Key", mSMIMEEncryptionKey.data());
367 config->writeEntry(
"Preferred Crypto Message Format", Kleo::cryptoMessageFormatToString( mPreferredCryptoMessageFormat ) );
368 config->writeEntry(
"Email Address", mEmailAddr);
369 config->writeEntry(
"Email Aliases", mEmailAliases);
370 config->writeEntry(
"Reply-To Address", mReplyToAddr);
371 config->writeEntry(
"Bcc", mBcc);
372 config->writePathEntry(
"VCardFile", mVCardFile);
373 config->writeEntry(
"Transport", mTransport);
374 config->writeEntry(
"Fcc", mFcc);
375 config->writeEntry(
"Drafts", mDrafts);
376 config->writeEntry(
"Templates", mTemplates);
377 config->writeEntry(
"Dictionary", mDictionary );
378 config->writeEntry(
"X-Face", mXFace );
379 config->writeEntry(
"X-FaceEnabled", mXFaceEnabled );
381 mSignature.writeConfig( config );
384 TQDataStream & KPIM::operator<<( TQDataStream & stream,
const KPIM::Identity & i ) {
385 return stream << static_cast<TQ_UINT32>(i.
uoid())
405 << TQString( Kleo::cryptoMessageFormatToString( i.mPreferredCryptoMessageFormat ) );
408 TQDataStream & KPIM::operator>>( TQDataStream & stream,
KPIM::Identity & i ) {
416 >> i.mPGPEncryptionKey
417 >> i.mSMIMESigningKey
418 >> i.mSMIMEEncryptionKey
433 i.mPreferredCryptoMessageFormat = Kleo::stringToCryptoMessageFormat( format.latin1() );
441 return !mEmailAddr.isEmpty();
449 void Identity::setIdentityName(
const TQString & name ) {
453 void Identity::setFullName(
const TQString &str)
460 void Identity::setOrganization(
const TQString &str)
465 void Identity::setPGPSigningKey(
const TQCString &str)
467 mPGPSigningKey = str;
468 if ( mPGPSigningKey.isNull() )
472 void Identity::setPGPEncryptionKey(
const TQCString &str)
474 mPGPEncryptionKey = str;
475 if ( mPGPEncryptionKey.isNull() )
476 mPGPEncryptionKey =
"";
479 void Identity::setSMIMESigningKey(
const TQCString &str)
481 mSMIMESigningKey = str;
482 if ( mSMIMESigningKey.isNull() )
483 mSMIMESigningKey =
"";
486 void Identity::setSMIMEEncryptionKey(
const TQCString &str)
488 mSMIMEEncryptionKey = str;
489 if ( mSMIMEEncryptionKey.isNull() )
490 mSMIMEEncryptionKey =
"";
494 void Identity::setPrimaryEmailAddress(
const TQString & str )
499 void Identity::setEmailAliases(
const TQStringList & list )
501 mEmailAliases = list;
504 bool Identity::matchesEmailAddress(
const TQString & addr )
const
506 const TQString lower = addr.lower();
507 if ( lower == mEmailAddr.lower() )
509 for ( TQStringList::const_iterator it = mEmailAliases.begin(), end = mEmailAliases.end() ; it != end ; ++it )
510 if ( (*it).lower() == lower )
516 void Identity::setVCardFile(
const TQString &str)
525 if (mFullName.isEmpty())
return mEmailAddr;
527 const TQString specials(
"()<>@,.;:[]");
532 bool needsQuotes=
false;
533 for (
unsigned int i=0; i < mFullName.length(); i++) {
534 if ( specials.contains( mFullName[i] ) )
536 else if ( mFullName[i] ==
'\\' || mFullName[i] ==
'"' ) {
540 result += mFullName[i];
544 result.insert(0,
'"');
548 result +=
" <" + mEmailAddr +
'>';
554 void Identity::setReplyToAddr(
const TQString& str)
561 void Identity::setSignatureFile(
const TQString &str)
568 void Identity::setSignatureInlineText(
const TQString &str )
575 void Identity::setTransport(
const TQString &str )
578 if ( mTransport.isNull() )
583 void Identity::setFcc(
const TQString &str )
591 void Identity::setDrafts(
const TQString &str )
594 if ( mDrafts.isNull() )
599 void Identity::setTemplates(
const TQString &str )
602 if ( mTemplates.isNull() )
607 void Identity::setDictionary(
const TQString &str )
610 if ( mDictionary.isNull() )
616 void Identity::setXFace(
const TQString &str )
619 mXFace.remove(
" " );
620 mXFace.remove(
"\n" );
621 mXFace.remove(
"\r" );
626 void Identity::setXFaceEnabled(
const bool on )
635 bool internalOK =
false;
645 if ( ok ) *ok =
false;
648 #if 0 // ### FIXME: error handling
649 if (mSignatureFile.endsWith(
"|"))