[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kmail-devel
Subject:    Re: [PATCH part 2] Use the Kpgp key handling also with the OpenPGP plugin
From:       Ingo =?iso-8859-1?q?Kl=F6cker?= <kloecker () kde ! org>
Date:       2002-09-29 18:56:54
[Download RAW message or body]

[Attachment #2 (multipart/mixed)]


Hi,

here is part two of the patch. ;-)

Regards,
Ingo


["libkdenetwork.diff" (text/x-diff)]

Index: kpgp.cpp
===================================================================
RCS file: /home/kde/kdenetwork/libkdenetwork/kpgp.cpp,v
retrieving revision 1.57
diff -u -3 -p -r1.57 kpgp.cpp
--- kpgp.cpp	2002/09/18 21:42:17	1.57
+++ kpgp.cpp	2002/09/29 18:24:10
@@ -305,7 +305,6 @@ Module::encrypt( Block& block,
                  bool sign, const QCString& charset )
 {
   KeyIDList encryptionKeyIds; // list of keys which are used for encryption
-  bool showKeysForApproval = false;
   int status = 0;
   errMsg = "";
 
@@ -314,118 +313,11 @@ Module::encrypt( Block& block,
   setUser( keyId );
 
   if( !receivers.empty() ) {
-    // list of lists of encryption keys (one list per recipient + one list
-    // for the sender)
-    QValueVector<KeyIDList> recipientKeyIds( receivers.count()+1 );
-    // add the sender's encryption key(s) to the list of recipient key IDs
-    if( encryptToSelf() ) {
-      recipientKeyIds[0] = KeyIDList( keyId );
-    }
-    else {
-      recipientKeyIds[0] = KeyIDList();
-    }
-    int i = 1;
-    for( QStringList::ConstIterator it = receivers.begin();
-         it != receivers.end(); ++it, ++i ) {
-      EncryptPref encrPref = encryptionPreference( *it );
-      if( ( encrPref == UnknownEncryptPref ) || ( encrPref == NeverEncrypt ) )
-        showKeysForApproval = true;
-
-      KeyIDList keyIds = getEncryptionKeys( *it );
-      if( keyIds.isEmpty() ) {
-        showKeysForApproval = true;
-      }
-      recipientKeyIds[i] = keyIds;
-    }
-
-    kdDebug(5100) << "recipientKeyIds = (\n";
-    QValueVector<KeyIDList>::const_iterator kit;
-    for( kit = recipientKeyIds.begin(); kit != recipientKeyIds.end(); ++kit ) {
-      kdDebug(5100) << "( 0x" << (*kit).toStringList().join( ", 0x" )
-                    << " ),\n";
-    }
-    kdDebug(5100) << ")\n";
-
-    if( showKeysForApproval || mShowKeyApprovalDlg ) {
-      unsigned int allowedKeys = PublicKeys | EncryptionKeys | ValidKeys;
-#if 0
-      // ### reenable this code when we support encryption with untrusted keys
-      if( pgpType != tGPG ) {
-        // usage of untrusted keys is only possible with GnuPG
-        allowedKeys |= TrustedKeys;
-      }
-#endif
-      // show the receivers <-> key relation
-      KeyApprovalDialog dlg( receivers, recipientKeyIds, allowedKeys );
-
-      int n = 0;
-      while( this->isBusy() ) { n++; this->idle(); }
-      int ret = dlg.exec();
-      for( int j = 0; j < n; j++ ) this->setBusy();
-      if( ret == QDialog::Rejected )
-        return Kpgp::Canceled;
-
-      recipientKeyIds = dlg.keys();
-    }
-
-    // flatten the list of lists of key IDs and count empty key ID lists
-    unsigned int emptyListCount = 0;
-    for( QValueVector<KeyIDList>::const_iterator it = recipientKeyIds.begin();
-         it != recipientKeyIds.end(); ++it ) {
-      if( (*it).isEmpty() ) {
-        emptyListCount++;
-      }
-      else {
-        for( KeyIDList::ConstIterator kit = (*it).begin();
-             kit != (*it).end(); kit++ ) {
-          encryptionKeyIds.append( *kit );
-        }
-      }
+    Kpgp::Result result = getEncryptionKeys( encryptionKeyIds, receivers,
+                                             keyId );
+    if( Kpgp::Ok != result ) {
+      return result;
     }
-
-    // show a warning if the user didn't select an encryption key for
-    // some of the recipients
-    if( recipientKeyIds.size() == emptyListCount + 1 ) { // (+1 because of the sender's key)
-      QString str = ( receivers.count() == 1 )
-                    ? i18n("You didn't select an encryption key for the "
-                           "recipient of this message. Therefore the message "
-                           "will not be encrypted.")
-                    : i18n("You didn't select an encryption key for any of the "
-                           "recipients of this message. Therefore the message "
-                           "will not be encrypted.");
-      int n = 0;
-      while( this->isBusy() ) { n++; this->idle(); }
-      int ret = KMessageBox::warningContinueCancel( 0, str,
-                                                    i18n("PGP Warning"),
-                                                    i18n("Send &Unencrypted") );
-      for( int j = 0; j < n; j++ ) this->setBusy();
-      if( ret == KMessageBox::Cancel ) {
-        return Kpgp::Canceled;
-      }
-    }
-    else if( emptyListCount > 0 ) {
-      QString str = ( emptyListCount == 1 )
-                    ? i18n("You didn't select an encryption key for one of "
-                           "the recipients. This person will not be able to "
-                           "decrypt the message if you encrypt it.")
-                    : i18n("You didn't select encryption keys for some of "
-                           "the recipients. These persons will not be able to "
-                           "decrypt the message if you encrypt it." );
-      int n = 0;
-      while( this->isBusy() ) { n++; this->idle(); }
-      int ret = KMessageBox::warningYesNoCancel( 0, str,
-                                                 i18n("PGP Warning"),
-                                                 i18n("Send &Encrypted"),
-                                                 i18n("Send &Unencrypted") );
-      for( int j = 0; j < n; j++ ) this->setBusy();
-      if( ret == KMessageBox::Cancel ) {
-        return Kpgp::Canceled;
-      }
-      else if( ret == KMessageBox::No ) {
-        // the user selected "Send unencrypted"
-        recipientKeyIds.clear();
-      }
-    }
   }
 
   status = doEncSign( block, encryptionKeyIds, sign );
@@ -584,6 +476,135 @@ Module::doEncSign( Block& block,
   cleanupPass();
 
   return retval;
+}
+
+Kpgp::Result
+Module::getEncryptionKeys( KeyIDList& encryptionKeyIds,
+                           const QStringList& recipients,
+                           const KeyID& keyId )
+{
+  if( recipients.empty() ) {
+    encryptionKeyIds.clear();
+    return Kpgp::Ok;
+  }
+
+  // list of lists of encryption keys (one list per recipient + one list
+  // for the sender)
+  QValueVector<KeyIDList> recipientKeyIds( recipients.count() + 1 );
+  // add the sender's encryption key(s) to the list of recipient key IDs
+  if( encryptToSelf() ) {
+    recipientKeyIds[0] = KeyIDList( keyId );
+  }
+  else {
+    recipientKeyIds[0] = KeyIDList();
+  }
+  bool showKeysForApproval = false;
+  int i = 1;
+  for( QStringList::ConstIterator it = recipients.begin();
+       it != recipients.end(); ++it, ++i ) {
+    EncryptPref encrPref = encryptionPreference( *it );
+    if( ( encrPref == UnknownEncryptPref ) || ( encrPref == NeverEncrypt ) )
+      showKeysForApproval = true;
+
+    KeyIDList keyIds = getEncryptionKeys( *it );
+    if( keyIds.isEmpty() ) {
+      showKeysForApproval = true;
+    }
+    recipientKeyIds[i] = keyIds;
+  }
+
+  kdDebug(5100) << "recipientKeyIds = (\n";
+  QValueVector<KeyIDList>::const_iterator kit;
+  for( kit = recipientKeyIds.begin(); kit != recipientKeyIds.end(); ++kit ) {
+    kdDebug(5100) << "( 0x" << (*kit).toStringList().join( ", 0x" )
+                  << " ),\n";
+  }
+  kdDebug(5100) << ")\n";
+
+  if( showKeysForApproval || mShowKeyApprovalDlg ) {
+    // #### FIXME: Until we support encryption with untrusted keys only
+    // ####        trusted keys are allowed
+    unsigned int allowedKeys = PublicKeys | EncryptionKeys | ValidKeys | TrustedKeys;
+#if 0
+    // ### reenable this code when we support encryption with untrusted keys
+    if( pgpType != tGPG ) {
+      // usage of untrusted keys is only possible with GnuPG
+      allowedKeys |= TrustedKeys;
+    }
+#endif
+    // show the recipients <-> key relation
+    KeyApprovalDialog dlg( recipients, recipientKeyIds, allowedKeys );
+
+    int n = 0;
+    while( this->isBusy() ) { n++; this->idle(); }
+    int ret = dlg.exec();
+    for( int j = 0; j < n; j++ ) this->setBusy();
+    if( ret == QDialog::Rejected )
+      return Kpgp::Canceled;
+
+    recipientKeyIds = dlg.keys();
+  }
+
+  // flatten the list of lists of key IDs and count empty key ID lists
+  unsigned int emptyListCount = 0;
+  for( QValueVector<KeyIDList>::const_iterator it = recipientKeyIds.begin();
+       it != recipientKeyIds.end(); ++it ) {
+    if( (*it).isEmpty() ) {
+      emptyListCount++;
+    }
+    else {
+      for( KeyIDList::ConstIterator kit = (*it).begin();
+           kit != (*it).end(); kit++ ) {
+        encryptionKeyIds.append( *kit );
+      }
+    }
+  }
+
+  // show a warning if the user didn't select an encryption key for
+  // some of the recipients
+  if( recipientKeyIds.size() == emptyListCount + 1 ) { // (+1 because of the sender's key)
+    QString str = ( recipients.count() == 1 )
+                  ? i18n("You didn't select an encryption key for the "
+                         "recipient of this message. Therefore the message "
+                         "will not be encrypted.")
+                  : i18n("You didn't select an encryption key for any of the "
+                         "recipients of this message. Therefore the message "
+                         "will not be encrypted.");
+    int n = 0;
+    while( this->isBusy() ) { n++; this->idle(); }
+    int ret = KMessageBox::warningContinueCancel( 0, str,
+                                                  i18n("PGP Warning"),
+                                                  i18n("Send &Unencrypted") );
+    for( int j = 0; j < n; j++ ) this->setBusy();
+    if( ret == KMessageBox::Cancel ) {
+      return Kpgp::Canceled;
+    }
+  }
+  else if( emptyListCount > 0 ) {
+    QString str = ( emptyListCount == 1 )
+                  ? i18n("You didn't select an encryption key for one of "
+                         "the recipients. This person will not be able to "
+                         "decrypt the message if you encrypt it.")
+                  : i18n("You didn't select encryption keys for some of "
+                         "the recipients. These persons will not be able to "
+                         "decrypt the message if you encrypt it." );
+    int n = 0;
+    while( this->isBusy() ) { n++; this->idle(); }
+    int ret = KMessageBox::warningYesNoCancel( 0, str,
+                                               i18n("PGP Warning"),
+                                               i18n("Send &Encrypted"),
+                                               i18n("Send &Unencrypted") );
+    for( int j = 0; j < n; j++ ) this->setBusy();
+    if( ret == KMessageBox::Cancel ) {
+      return Kpgp::Canceled;
+    }
+    else if( ret == KMessageBox::No ) {
+      // the user selected "Send unencrypted"
+      encryptionKeyIds.clear();
+    }
+  }
+
+  return Kpgp::Ok;
 }
 
 int
Index: kpgp.h
===================================================================
RCS file: /home/kde/kdenetwork/libkdenetwork/kpgp.h,v
retrieving revision 1.27
diff -u -3 -p -r1.27 kpgp.h
--- kpgp.h	2002/08/29 19:36:45	1.27
+++ kpgp.h	2002/09/29 18:24:11
@@ -113,7 +113,7 @@ public:
       Returns
       Failure  if there was an unresolvable error
       Canceled if signing was canceled
-      OK       if everything is o.k.
+      Ok       if everything is o.k.
   */
   Kpgp::Result clearsign( Block& block,
                   const KeyID& keyId, const QCString& charset = 0 );
@@ -124,11 +124,22 @@ public:
       Returns
       Failure  if there was an unresolvable error
       Canceled if encryption was canceled
-      OK       if everything is o.k.
+      Ok       if everything is o.k.
   */
   Kpgp::Result encrypt( Block& block,
                 const QStringList& receivers, const KeyID& keyId,
                 bool sign, const QCString& charset = 0 );
+
+  /** Determines the keys which should be used for encrypting the message
+      to the given list of recipients.
+      Returns:
+      Failure  if there was an unresolvable error
+      Canceled if encryption was canceled
+      Ok       if everything is o.k.
+  */
+  Kpgp::Result getEncryptionKeys( KeyIDList& encryptionKeyIds,
+                                  const QStringList& recipients,
+                                  const KeyID& keyId );
 
   /** checks if encrypting to the given list of persons is possible and
       desired, i.e. if we have a (trusted) key for every recipient and

[Attachment #6 (application/pgp-signature)]
_______________________________________________
KMail Developers mailing list
kmail@mail.kde.org
http://mail.kde.org/mailman/listinfo/kmail

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic