Fixed.
[riece] / lisp / riece-epg.el
index b999eeb..355b9c9 100644 (file)
@@ -44,7 +44,7 @@
 
 (defvar riece-epg-passphrase-alist nil)
 
-(defun riece-epg-passphrase-callback-function (key-id identity)
+(defun riece-epg-passphrase-callback-function (context key-id identity)
   (if (eq key-id 'SYM)
       (let ((entry (riece-identity-assoc identity riece-epg-passphrase-alist))
            passphrase)
                (setq entry (list identity)
                      riece-epg-passphrase-alist (cons entry
                                                 riece-epg-passphrase-alist)))
-             (setq passphrase (epg-passphrase-callback-function key-id nil))
+             (setq passphrase (epg-passphrase-callback-function context
+                                                                key-id nil))
              (setcdr entry (copy-sequence passphrase))
              passphrase)))
-    (epg-passphrase-callback-function key-id nil)))
+    (epg-passphrase-callback-function context key-id nil)))
 
-(defun riece-epg-passphrase-callback-function-for-decrypt (key-id identity)
+(defun riece-epg-passphrase-callback-function-for-decrypt (context key-id
+                                                                  identity)
   (if (eq key-id 'SYM)
       (let ((entry (riece-identity-assoc identity riece-epg-passphrase-alist))
            passphrase)
        (if (cdr entry)
            (copy-sequence (cdr entry))
-         (epg-cancel epg-context)))
-    (epg-passphrase-callback-function key-id nil)))
+         (epg-cancel context)))
+    (epg-passphrase-callback-function context key-id nil)))
 
 (defun riece-epg-funcall-clear-passphrase (identity function &rest args)
   (condition-case error
      (signal (car error) (cdr error)))))
   
 (defun riece-command-enter-encrypted-message ()
-  "Encrypt the current line send send it to the current channel."
+  "Encrypt the current line and send it to the current channel."
   (interactive)
   (let ((context (epg-make-context))
-       (string (buffer-substring
-                (riece-line-beginning-position)
-                (riece-line-end-position)))
+       (string (buffer-substring (riece-line-beginning-position)
+                                 (riece-line-end-position)))
        entry)
-    (riece-with-server-buffer (riece-identity-server riece-current-channel)
-      (setq string (riece-encode-coding-string-for-identity
-                   string
-                   riece-current-channel)))
     (epg-context-set-passphrase-callback
      context
      (cons #'riece-epg-passphrase-callback-function
           riece-current-channel))
-    (setq string (riece-epg-funcall-clear-passphrase riece-current-channel
-                                                    #'epg-encrypt-string
-                                                    context string nil))
-    (riece-command-send-message
-     (concat "[encrypted:" (base64-encode-string string t) "]")
-     nil)
+    (riece-send-string
+     (format "PRIVMSG %s :[encrypted:%s]\r\n"
+            (riece-identity-prefix riece-current-channel)
+            (base64-encode-string
+             (riece-epg-funcall-clear-passphrase
+              riece-current-channel
+              #'epg-encrypt-string
+              context
+              (riece-with-server-buffer
+                  (riece-identity-server riece-current-channel)
+                (riece-encode-coding-string-for-identity
+                 string
+                 riece-current-channel))
+              nil)
+             t)))
+    (riece-display-message
+     (riece-make-message (riece-current-nickname) riece-current-channel
+                        (concat "[decrypted:" string "]") nil t))
     (let ((next-line-add-newlines t))
       (next-line 1))))
 
              (progn
                (riece-message-set-text
                 message
-                (concat
-                 "[decrypted:"
-                 (riece-epg-decrypt-string-for-identity
-                  context string (riece-message-target message))
-                 "]")))
+                (format "[decrypted:%s]"
+                        (riece-epg-decrypt-string-for-identity
+                         context string (riece-message-target message)))))
            (error
             (riece-put-text-property-nonsticky
              0 (length (riece-message-text message))
              'riece-epg-encryption-target (riece-message-target message)
              (riece-message-text message))
-            (message "%s" (cdr error)))))))
+            (if riece-debug
+                (message "Couldn't decrypt: %s" (cdr error))
+              (message "Couldn't decrypt")))))))
   message)
 
 (defun riece-epg-add-encrypted-button (start end)