decrypted -> encrypted.
[riece] / lisp / riece-epg.el
index 8f7cf80..6c1c77f 100644 (file)
@@ -26,6 +26,7 @@
 (require 'riece-message)
 (require 'riece-identity)
 
+(autoload 'widget-convert-button "wid-edit")
 (autoload 'epg-make-context "epg")
 (autoload 'epg-decrypt-string "epg")
 (autoload 'epg-encrypt-string "epg")
@@ -63,8 +64,7 @@
 (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)
+      (let ((entry (riece-identity-assoc identity riece-epg-passphrase-alist)))
        (if (cdr entry)
            (copy-sequence (cdr entry))
          (epg-cancel context)))
      (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)))
-       entry)
-    (riece-with-server-buffer (riece-identity-server riece-current-channel)
-      (setq string (riece-encode-coding-string-for-identity
-                   string
-                   riece-current-channel)))
+       (string (buffer-substring (riece-line-beginning-position)
+                                 (riece-line-end-position))))
     (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 "[encrypted:" string "]") nil t))
     (let ((next-line-add-newlines t))
       (next-line 1))))
 
       (when (string-match "\\`\\[encrypted:\\(.*\\)]"
                          (riece-message-text message))
        (let ((context (epg-make-context))
-             (string (match-string 1 (riece-message-text message)))
-             entry)
+             (string (match-string 1 (riece-message-text message))))
          (epg-context-set-passphrase-callback
           context
           (cons #'riece-epg-passphrase-callback-function-for-decrypt
              (progn
                (riece-message-set-text
                 message
-                (concat
-                 "[decrypted:"
-                 (riece-epg-decrypt-string-for-identity
-                  context string (riece-message-target message))
-                 "]")))
+                (format "[encrypted:%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)
       (delete-region from to)
       (save-excursion
        (goto-char from)
-       (insert "[decrypted:" plain "]")))))
+       (insert "[encrypted:" plain "]")))))
 
 (defun riece-epg-requires ()
   (if (memq 'riece-button riece-addons)