Revision: 7395
          http://mahogany.svn.sourceforge.net/mahogany/?rev=7395&view=rev
Author:   vadz
Date:     2007-12-09 16:11:03 -0800 (Sun, 09 Dec 2007)

Log Message:
-----------
don't ask whether to retrieve the public key from keyserver, this becomes 
annoying (especially for the keys not present on the server) but disabling the 
message box is bad too as you do want to be able to get the keys automatically 
-- so instead let the user do it by clicking on the PGPClickable

Modified Paths:
--------------
    trunk/M/include/Moptions.h
    trunk/M/include/MpersIds.h
    trunk/M/include/PGPClickInfo.h
    trunk/M/include/modules/MCrypt.h
    trunk/M/src/classes/Moptions.cpp
    trunk/M/src/classes/Mpers.cpp
    trunk/M/src/classes/PGPClickInfo.cpp
    trunk/M/src/gui/wxOptionsDlg.cpp
    trunk/M/src/modules/crypt/PGPEngine.cpp
    trunk/M/src/modules/viewflt/PGP.cpp
    trunk/M/src/util/upgrade.cpp

Modified: trunk/M/include/Moptions.h
===================================================================
--- trunk/M/include/Moptions.h  2007-12-10 00:01:34 UTC (rev 7394)
+++ trunk/M/include/Moptions.h  2007-12-10 00:11:03 UTC (rev 7395)
@@ -356,7 +356,6 @@
 extern const MOption MP_ALWAYS_USE_EXTERNALEDITOR;
 extern const MOption MP_PGP_COMMAND;
 extern const MOption MP_PGP_KEYSERVER;
-extern const MOption MP_PGP_GET_PUBKEY;
 extern const MOption MP_USE_NEWMAILCOMMAND;
 extern const MOption MP_NEWMAILCOMMAND;
 extern const MOption MP_NEWMAIL_PLAY_SOUND;
@@ -1111,8 +1110,6 @@
 #define MP_PGP_COMMAND_NAME    "PGPCommand"
 /// PGP/GPG key server for public keys
 #define MP_PGP_KEYSERVER_NAME  "PGPKeyServer"
-/// get PGP key from server?
-#define MP_PGP_GET_PUBKEY_NAME  "PGPGetPubKey"
 /// execute a command when new mail arrives?
 #define   MP_USE_NEWMAILCOMMAND_NAME      "CommandOnNewMail"
 /// command to execute when new mail arrives
@@ -2098,8 +2095,6 @@
 
 /// PGP/GPG key server for public keys
 #define MP_PGP_KEYSERVER_DEFVAL "wwwkeys.eu.pgp.net"
-/// get PGP key from server?
-#define MP_PGP_GET_PUBKEY_DEFVAL 1l
 
 /// command to execute when new mail arrives
 #define   MP_USE_NEWMAILCOMMAND_DEFVAL   0l

Modified: trunk/M/include/MpersIds.h
===================================================================
--- trunk/M/include/MpersIds.h  2007-12-10 00:01:34 UTC (rev 7394)
+++ trunk/M/include/MpersIds.h  2007-12-10 00:11:03 UTC (rev 7395)
@@ -110,7 +110,6 @@
 DECL_OR_DEF(ZAP_SPAM);
 
 DECL_OR_DEF(REMEMBER_PGP_PASSPHRASE);
-DECL_OR_DEF(GET_PGP_PUBKEY);
 
 DECL_OR_DEF(SEARCH_AGAIN_IF_NO_MATCH);
 

Modified: trunk/M/include/PGPClickInfo.h
===================================================================
--- trunk/M/include/PGPClickInfo.h      2007-12-10 00:01:34 UTC (rev 7394)
+++ trunk/M/include/PGPClickInfo.h      2007-12-10 00:11:03 UTC (rev 7395)
@@ -33,9 +33,10 @@
 
    /// create the object corresponding to the given signature check status code
    static ClickablePGPInfo *
-   CreateFromSigStatusCode(MCryptoEngine::Status code,
+   CreateFromSigStatusCode(MCryptoEngine *pgpEngine,
+                           MCryptoEngine::Status code,
                            MessageView *msgView,
-                           const MCryptoEngineOutputLog *log);
+                           MCryptoEngineOutputLog *log);
 
 
    // implement the base class pure virtuals
@@ -169,14 +170,31 @@
 class PGPInfoKeyNotFoundSig : public PGPSignatureInfo
 {
 public:
-   PGPInfoKeyNotFoundSig(MessageView *msgView, const String& from)
+   PGPInfoKeyNotFoundSig(MessageView *msgView,
+                         const String& from,
+                         MCryptoEngine *engine,
+                         MCryptoEngineOutputLog *log)
       : PGPSignatureInfo(msgView,
-                         wxString::Format(_("PGP public key not found%s"),
-                                          GetFromString(from).c_str()),
+                         wxString::Format
+                         (
+                           _("PGP public key not found%s, click here to "
+                             "try to retrieve it."),
+                           GetFromString(from).c_str()
+                         ),
                          _T("pgpsig_bad"),
-                         wxColour(145, 145, 145)) { }
+                         wxColour(145, 145, 145)),
+        m_engine(engine),
+        m_log(log)
+   {
+   }
 
+   // override this to get the missing key from server
+   virtual void OnLeftClick(const wxPoint&) const;
+
 private:
+   MCryptoEngine * const m_engine;
+   MCryptoEngineOutputLog * const m_log;
+
    DECLARE_NO_COPY_CLASS(PGPInfoKeyNotFoundSig)
 };
 

Modified: trunk/M/include/modules/MCrypt.h
===================================================================
--- trunk/M/include/modules/MCrypt.h    2007-12-10 00:01:34 UTC (rev 7394)
+++ trunk/M/include/modules/MCrypt.h    2007-12-10 00:11:03 UTC (rev 7395)
@@ -145,18 +145,32 @@
                               const String& signature,
                               MCryptoEngineOutputLog *log = NULL) = 0;
 
-#if 0
-   virtual Status CheckRecipient(const String & recipient) const = 0;
+   //@}
 
-   virtual Status GetFingerprint(String & fp) const = 0;
+   /// @name Key management.
+   //@{
 
-   virtual Status GetPublicKey(String & pk) const = 0;
-#endif // 0
+   /**
+      Attempt to retrieve the specified public key from a public key server.
+
+      @param pk the public key to retrieve
+      @param server the server to get it from
+    */
+   virtual Status GetPublicKey(const String& pk,
+                               const String& server,
+                               MCryptoEngineOutputLog *log) const = 0;
+
    //@}
 
+   // TODO
+#if 0
    /** @name Other */
    //@{
 
+   virtual Status CheckRecipient(const String & recipient) const = 0;
+
+   virtual Status GetFingerprint(String & fp) const = 0;
+
    /**
       Shows the engine configuration dialog.
 
@@ -165,6 +179,7 @@
    //virtual void Configure(wxWindow *parent) = 0;
 
    //@}
+#endif // 0
 
 protected:
    /// virtual dtor

Modified: trunk/M/src/classes/Moptions.cpp
===================================================================
--- trunk/M/src/classes/Moptions.cpp    2007-12-10 00:01:34 UTC (rev 7394)
+++ trunk/M/src/classes/Moptions.cpp    2007-12-10 00:11:03 UTC (rev 7395)
@@ -414,7 +414,6 @@
 const MOption MP_ALWAYS_USE_EXTERNALEDITOR;
 const MOption MP_PGP_COMMAND;
 const MOption MP_PGP_KEYSERVER;
-const MOption MP_PGP_GET_PUBKEY;
 const MOption MP_USE_NEWMAILCOMMAND;
 const MOption MP_NEWMAILCOMMAND;
 const MOption MP_NEWMAIL_PLAY_SOUND;
@@ -831,7 +830,6 @@
     DEFINE_OPTION(MP_ALWAYS_USE_EXTERNALEDITOR),
     DEFINE_OPTION(MP_PGP_COMMAND),
     DEFINE_OPTION(MP_PGP_KEYSERVER),
-    DEFINE_OPTION(MP_PGP_GET_PUBKEY),
     DEFINE_OPTION(MP_USE_NEWMAILCOMMAND),
     DEFINE_OPTION(MP_NEWMAILCOMMAND),
     DEFINE_OPTION(MP_NEWMAIL_PLAY_SOUND),

Modified: trunk/M/src/classes/Mpers.cpp
===================================================================
--- trunk/M/src/classes/Mpers.cpp       2007-12-10 00:01:34 UTC (rev 7394)
+++ trunk/M/src/classes/Mpers.cpp       2007-12-10 00:11:03 UTC (rev 7395)
@@ -158,7 +158,6 @@
    { "ConfirmZap",               gettext_noop("confirm permanently deleting 
messages") },
    { "ZapSpam",                  gettext_noop("permanently delete message 
after marking them as spam") },
    { "RememberPGPPassphrase",    gettext_noop("remember PGP/GPG passphrase in 
memory") },
-   { "GetPGPPubKey",             gettext_noop("retrieve PGP/GPG public keys 
from key server") },
    { "SearchAgainIfNoMatch",     gettext_noop("propose to search again if no 
matches were found") },
    { "UseCreateFolderWizard",    gettext_noop("use wizard when creating a new 
folder") },
    { "FormatParagraphBeforeExit",gettext_noop("format all paragraphs in 
composer before exit") },

Modified: trunk/M/src/classes/PGPClickInfo.cpp
===================================================================
--- trunk/M/src/classes/PGPClickInfo.cpp        2007-12-10 00:01:34 UTC (rev 
7394)
+++ trunk/M/src/classes/PGPClickInfo.cpp        2007-12-10 00:11:03 UTC (rev 
7395)
@@ -36,6 +36,8 @@
 
 #include "PGPClickInfo.h"
 
+extern const MOption MP_PGP_KEYSERVER;
+
 // ----------------------------------------------------------------------------
 // PGPMenu: used by ClickablePGPInfo
 // ----------------------------------------------------------------------------
@@ -124,9 +126,10 @@
 
 /* static */
 ClickablePGPInfo *
-ClickablePGPInfo::CreateFromSigStatusCode(MCryptoEngine::Status code,
+ClickablePGPInfo::CreateFromSigStatusCode(MCryptoEngine *engine,
+                                          MCryptoEngine::Status code,
                                           MessageView *msgView,
-                                          const MCryptoEngineOutputLog *log)
+                                          MCryptoEngineOutputLog *log)
 {
    ClickablePGPInfo *pgpInfo;
    const String& user = log->GetUserID();
@@ -157,7 +160,7 @@
          break;
 
       case MCryptoEngine::NONEXISTING_KEY_ERROR:
-         pgpInfo = new PGPInfoKeyNotFoundSig(msgView, user);
+         pgpInfo = new PGPInfoKeyNotFoundSig(msgView, user, engine, log);
          break;
 
       default:
@@ -254,4 +257,40 @@
                     _T("PGPRawText"));
 }
 
+// ----------------------------------------------------------------------------
+// PGPInfoKeyNotFoundSig
+// ----------------------------------------------------------------------------
 
+void PGPInfoKeyNotFoundSig::OnLeftClick(const wxPoint&) const
+{
+   MessageView * const mview = GetMessageView();
+   CHECK_RET( mview, "should have the associated message view" );
+
+   String keyserver = READ_APPCONFIG_TEXT(MP_PGP_KEYSERVER);
+   if ( keyserver.empty() )
+   {
+      if ( !MInputBox
+            (
+               &keyserver,
+               _("Public key server"),
+               _("Please enter GPG public ket server:"),
+               mview->GetWindow(),
+               "PGPKeyServer"
+            ) )
+      {
+         // cancelled by user
+         return;
+      }
+   }
+
+   if ( m_engine->GetPublicKey(m_log->GetPublicKey(), keyserver, m_log) ==
+            MCryptoEngine::OK )
+   {
+      // force the message view to refresh this message: we can now decrypt it
+      // or verify its signature
+      const UIdType uidOld = mview->GetUId();
+      mview->ShowMessage(UID_ILLEGAL);
+      mview->ShowMessage(uidOld);
+   }
+}
+

Modified: trunk/M/src/gui/wxOptionsDlg.cpp
===================================================================
--- trunk/M/src/gui/wxOptionsDlg.cpp    2007-12-10 00:01:34 UTC (rev 7394)
+++ trunk/M/src/gui/wxOptionsDlg.cpp    2007-12-10 00:11:03 UTC (rev 7395)
@@ -533,9 +533,8 @@
    ConfigField_PGPHelp,
    ConfigField_PGPCommand,
    ConfigField_PGPKeyServer,
-   ConfigField_PGPGetPubKey,
 
-   ConfigField_HelpersLast = ConfigField_PGPGetPubKey,
+   ConfigField_HelpersLast = ConfigField_PGPKeyServer,
 
 #ifdef USE_TEST_PAGE
    ConfigField_TestFirst = ConfigField_HelpersLast,
@@ -1748,10 +1747,10 @@
    { gettext_noop("\n"
                   "GNU Privacy Guard or a compatible program may be used\n"
                   "to verify the cryptographic signatures of the messages\n"
-                  "you receive and decrypt them."), Field_Message, -1 },
+                  "you receive and decrypt them. The public key server is\n"
+                  "used to retrieve the keys of the senders."), Field_Message, 
-1 },
    { gettext_noop("&GPG command"),                Field_File,    -1            
          },
-   { gettext_noop("GPG &key server"),             Field_Text,    -1            
          },
-   { gettext_noop("Get GPG key &from server"),    Field_Bool,    -1            
          },
+   { gettext_noop("GPG public &key server"),      Field_Text,    -1            
          },
 
    // test page
 #ifdef USE_TEST_PAGE
@@ -2249,7 +2248,6 @@
    CONFIG_NONE(), // PGP help
    CONFIG_ENTRY(MP_PGP_COMMAND),
    CONFIG_ENTRY(MP_PGP_KEYSERVER),
-   CONFIG_ENTRY(MP_PGP_GET_PUBKEY),
 
 #ifdef USE_TEST_PAGE
    CONFIG_NONE(),

Modified: trunk/M/src/modules/crypt/PGPEngine.cpp
===================================================================
--- trunk/M/src/modules/crypt/PGPEngine.cpp     2007-12-10 00:01:34 UTC (rev 
7394)
+++ trunk/M/src/modules/crypt/PGPEngine.cpp     2007-12-10 00:11:03 UTC (rev 
7395)
@@ -44,14 +44,12 @@
 
 extern const MOption MP_PGP_COMMAND;
 extern const MOption MP_PGP_KEYSERVER;
-extern const MOption MP_PGP_GET_PUBKEY;
 
 // ----------------------------------------------------------------------------
 // persistent msgboxes we use here
 // ----------------------------------------------------------------------------
 
 extern const MPersMsgBox *M_MSGBOX_REMEMBER_PGP_PASSPHRASE;
-extern const MPersMsgBox *M_MSGBOX_GET_PGP_PUBKEY;
 
 // ----------------------------------------------------------------------------
 // PassphraseManager: this class can be used to remember the passphrases
@@ -124,6 +122,10 @@
                                           const String& signature,
                                           MCryptoEngineOutputLog *log);
 
+   virtual Status GetPublicKey(const String& pk,
+                               const String& server,
+                               MCryptoEngineOutputLog *log) const;
+
 protected:
    /**
       Executes PGP/GPG with messageIn on stdin and puts stdout into messageOut.
@@ -552,70 +554,7 @@
                        String& messageOut,
                        MCryptoEngineOutputLog *log)
 {
-   Status status = DoExecCommand(options, messageIn, messageOut, log);
-   if ( status == NONEXISTING_KEY_ERROR && 
READ_APPCONFIG_BOOL(MP_PGP_GET_PUBKEY) ) //FIXME use Profile
-   {
-      // propose to the user to retrieve the key from a keyserver
-      if ( MDialog_Message
-           (
-               wxString::Format(
-                 _("This message was prepared using a public key which you "
-                   "don't have in the local keyring.\n"
-                   "\n"
-                   "Would you like to try to retrieve this public key "
-                   "(\"%s\") from the keyserver?"),
-                 log->GetPublicKey().c_str()
-               ),
-               log->GetParent(),
-               M_MSGBOX_GET_PGP_PUBKEY,
-               M_DLG_ALLOW_CANCEL
-           ) )
-      {
-         // try to get it
-
-         const String keyserver = READ_APPCONFIG_TEXT(MP_PGP_KEYSERVER);
-         status = DoExecCommand
-                  (
-                     wxString::Format
-                     (
-                        _T("--keyserver %s --recv-keys %s"),
-                        keyserver.c_str(),
-                        log->GetPublicKey().c_str()
-                     ),
-                     wxEmptyString,
-                     messageOut,
-                     log
-                  );
-
-         switch ( status )
-         {
-            default:
-               wxLogWarning(_("Importing public key failed for unknown "
-                              "reason."));
-               status = NONEXISTING_KEY_ERROR;
-               messageOut = messageIn;
-               break;
-
-            case NO_DATA_ERROR:
-               wxLogWarning(_("Public key not found on the key server 
\"%s\"."),
-                            keyserver.c_str());
-               status = NONEXISTING_KEY_ERROR;
-               messageOut = messageIn;
-               break;
-
-            case OK:
-               wxLogMessage(_("Successfully imported public key for \"%s\"."),
-                            log->GetUserID().c_str());
-
-               // try redoing the original command again
-               status = DoExecCommand(options, messageIn, messageOut, log);
-               break;
-         }
-      }
-      //else: key import cancelled by user
-   }
-
-   return status;
+   return DoExecCommand(options, messageIn, messageOut, log);
 }
 
 // ----------------------------------------------------------------------------
@@ -722,6 +661,49 @@
                       wxEmptyString, messageOut, log);
 }
 
+// ----------------------------------------------------------------------------
+// PGPEngine key management
+// ----------------------------------------------------------------------------
+
+PGPEngine::Status
+PGPEngine::GetPublicKey(const String& pk,
+                        const String& keyserver,
+                        MCryptoEngineOutputLog *log) const
+{
+   String dummyOut;
+   Status status = const_cast<PGPEngine *>(this)->DoExecCommand
+                   (
+                     wxString::Format
+                     (
+                        _T("--keyserver %s --recv-keys %s"),
+                        keyserver.c_str(),
+                        pk.c_str()
+                     ),
+                     wxEmptyString,
+                     dummyOut,
+                     log
+                   );
+   switch ( status )
+   {
+      default:
+         wxLogWarning(_("Importing public key failed for unknown "
+                        "reason."));
+         break;
+
+      case NO_DATA_ERROR:
+         wxLogWarning(_("Public key not found on the key server \"%s\"."),
+                      keyserver.c_str());
+         break;
+
+      case OK:
+         wxLogMessage(_("Successfully imported public key \"%s\"."),
+                      pk.c_str());
+         break;
+   }
+
+   return status;
+}
+
 // ============================================================================
 // PassphraseManager
 // ============================================================================

Modified: trunk/M/src/modules/viewflt/PGP.cpp
===================================================================
--- trunk/M/src/modules/viewflt/PGP.cpp 2007-12-10 00:01:34 UTC (rev 7394)
+++ trunk/M/src/modules/viewflt/PGP.cpp 2007-12-10 00:11:03 UTC (rev 7395)
@@ -296,7 +296,7 @@
             const MCryptoEngine::Status
                rc = m_engine->VerifySignature(in, out, log);
             pgpInfo = ClickablePGPInfo::
-                        CreateFromSigStatusCode(rc, m_msgView, log);
+                        CreateFromSigStatusCode(m_engine, rc, m_msgView, log);
 
             // if we failed to check the signature, we need to remove the
             // BEGIN/END lines from output ourselves (otherwise it would have

Modified: trunk/M/src/util/upgrade.cpp
===================================================================
--- trunk/M/src/util/upgrade.cpp        2007-12-10 00:01:34 UTC (rev 7394)
+++ trunk/M/src/util/upgrade.cpp        2007-12-10 00:11:03 UTC (rev 7395)
@@ -213,7 +213,8 @@
    Version_065,      // SSL flag is not boolean any more and not a flag at all
    Version_066,      // "/M/Profiles" -> "/Profiles"
    Version_067 = Version_066,     // no changes
-   Version_Last = Version_067,    // last existing version
+   Version_068,
+   Version_Last = Version_068,    // last existing version
    Version_Unknown   // some unrecognized version
 };
 
@@ -2796,6 +2797,20 @@
 }
 
 // ----------------------------------------------------------------------------
+// 0.66 -> 0.68
+// ----------------------------------------------------------------------------
+
+static bool
+UpgradeFrom066()
+{
+   // just purge the unnecessary MP_PGP_GET_PUBKEY and M_MSGBOX_GET_PGP_PUBKEY
+   mApplication->GetProfile()->DeleteEntry("PGPGetPubKey");
+   wxPMessageBoxEnable("GetPGPPubKey");
+
+   return true;
+}
+
+// ----------------------------------------------------------------------------
 // global functions
 // ----------------------------------------------------------------------------
 
@@ -2817,30 +2832,32 @@
          version.Truncate(version.Len() - 1);
 
       // trailing ".0" is not significant neither
-      if ( version.Right(2) == _T(".0") )
+      if ( version.Right(2) == ".0" )
          version.Truncate(version.Len() - 2);
 
-      if ( version == _T("0.01") )
+      if ( version == "0.01" )
          oldVersion = Version_Alpha001;
-      else if ( version == _T("0.02") || version == _T("0.10"))
+      else if ( version == "0.02" || version == "0.10")
          oldVersion = Version_Alpha010;
-      else if ( version == _T("0.20") )
+      else if ( version == "0.20" )
          oldVersion = Version_Alpha020;
-      else if ( version == _T("0.21") || version == _T("0.22") ||
-                version == _T("0.23") || version == _T("0.50") )
+      else if ( version == "0.21" || version == "0.22" ||
+                version == "0.23" || version == "0.50" )
          oldVersion = Version_050;
-      else if ( version == _T("0.60") )
+      else if ( version == "0.60" )
          oldVersion = Version_060;
-      else if ( version == _T("0.61") || version == _T("0.62") || version == 
_T("0.63") )
+      else if ( version == "0.61" || version == "0.62" || version == "0.63" )
          oldVersion = Version_061;
-      else if ( version == _T("0.64") )
+      else if ( version == "0.64" )
          oldVersion = Version_064;
-      else if ( version == _T("0.64.1") || version == _T("0.64.2") )
+      else if ( version == "0.64.1" || version == "0.64.2" )
          oldVersion = Version_064_1;
-      else if ( version == _T("0.65") )
+      else if ( version == "0.65" )
          oldVersion = Version_065;
-      else if ( version == _T("0.66") || version == _T("0.67") )
+      else if ( version == "0.66" || version == "0.67" )
          oldVersion = Version_066;
+      else if ( version == "0.68" )
+         oldVersion = Version_068;
       else
          oldVersion = Version_Unknown;
    }
@@ -2893,7 +2910,12 @@
          // fall through
 
       case Version_065:
-         if ( success && UpgradeFrom065() )
+         if ( success )
+            success = UpgradeFrom065();
+         // fall through
+
+      case Version_066:
+         if ( success && UpgradeFrom066() )
             wxLogMessage(_("Configuration information and program files were "
                            "successfully upgraded from the version '%s'."),
                          fromVersion.c_str());
@@ -2905,7 +2927,7 @@
                          "It is recommended that you uninstall and reinstall "
                          "the program before using it."),
                        fromVersion.c_str());
-         break;
+         // fall through
 
       case Version_Last:
          // nothing to do, it's the latest one


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
SF.Net email is sponsored by: 
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Mahogany-cvsupdates mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mahogany-cvsupdates

Reply via email to