<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,6 +1,7 @@
 ;;;; -*- indent-tabs-mode: nil -*-
 
 (require 'epg)
+(require 'url)
 
 (defun encrypt (str for-nick)
   (let ((context (epg-make-context 'OpenPGP)))
@@ -15,71 +16,65 @@
     (epg-context-set-armor context t)
     (epg-decrypt-string context str)))
 
-(defun erc-cmd-SENDENCRYPTED (recipient &amp;rest words)
-  (let* ((message (mapconcat 'identity words &quot; &quot;))
-         (ciphertext (encrypt message recipient))
-         (lines (split-string ciphertext &quot;\n&quot;)))
-    (dolist (line lines)
-      (erc-send-message line))))
-
-(setf *gpg-message-cache* (make-hash-table :test #'equal))
-(setf *gpg-nicks-sending-messages* nil)
-(setf *gpg-nicks-to-channels* (make-hash-table :test #'equal))
-
-(defun add-line (nick line)
-  (push line (gethash nick *gpg-message-cache*)))
-
-(defun clear-lines (nick)
-  (setf (gethash nick *gpg-message-cache*) nil))
-
-(defun get-encrypted-message (nick)
-  (let* ((lines (reverse (gethash nick *gpg-message-cache*)))
-         (ciphertext-body (mapconcat 'identity (cdr lines) &quot;\n&quot;)))
-    (mapconcat 'identity
-               (list &quot;-----BEGIN PGP MESSAGE-----&quot;
-                     (car lines) &quot;&quot; ciphertext-body
-                     &quot;-----END PGP MESSAGE-----&quot;)
-               &quot;\n&quot;)))
-
-(defun get-and-clear-encrypted-message (nick)
-  (prog1 (get-encrypted-message nick)
-    (clear-lines nick)))
-
-(defun listen-for (nick chan)
-  (print &quot;receiving encrypted message...&quot;)
-  (setf (gethash nick *gpg-nicks-to-channels*) chan)
-  (unless (member nick *gpg-nicks-sending-messages*)
-    (push nick *gpg-nicks-sending-messages*)))
-
-(defun stop-listen-for (nick)
-  (setf *gpg-nicks-sending-messages*
-        (remove nick *gpg-nicks-sending-messages*)))
+(defun erc-cmd-SENDENCRYPTED (nick &amp;rest words)
+  (let* ((message (mapconcat 'identity words &quot; &quot;)) 
+         (keyname (or (cdr (assoc nick *nickname-to-keyname*)) nick)) ;;TODO cdrassoc
+         (url (encrypt-and-paste-string message keyname)))
+    (erc-send-message (format &quot;%s: PGP MESSAGE %s&quot; nick url))))
 
 (defun find-buffer (name) (dolist (b (erc-buffer-list)) (if (equalp (buffer-name b) name) (return b))))
 
-(defun message-over (nick)
-  (stop-listen-for nick)
-  (print &quot;decrypting ciphertext...&quot;)
-  (let* ((ciphertext (get-and-clear-encrypted-message nick))
-         (plaintext (decrypt ciphertext))
-         (buffer-name (gethash nick *gpg-nicks-to-channels*))
-         (buffer (find-buffer buffer-name)))
-    (print plaintext)
-    (erc-display-message nil 'notice buffer plaintext))) ;;WTF IS THE BUFFER I SHOULD USE HERE?
+(defvar *nickname-to-keyname* nil
+  &quot;An alist associating irc nicknames with key identifiers&quot;)
+;TODO: move these to .ercrc.el
+(push '(&quot;bavardage&quot; . &quot;jebavarde&quot;) *nickname-to-keyname*)
+(push '(&quot;bavfoo&quot; . &quot;jebavarde&quot;) *nickname-to-keyname*)
+(push '(&quot;bavbar&quot; . &quot;jebavarde&quot;) *nickname-to-keyname*)
 
-(defun gpg-process (process parsed &amp;rest ignore)
+(defun listen-for-gpg-message (process parsed &amp;rest ignore)
   (let* ((sspec (aref parsed 1))
          (nick (substring (nth 0 (erc-parse-user sspec)) 1))
          (tgt (car (aref parsed 4)))
          (msg (aref parsed 5)))
-    (cond
-     ((equal msg &quot;-----BEGIN PGP MESSAGE-----&quot;)
-      (listen-for nick tgt)) ;;tgt isn't quite right :| since for queries it breaks
-     ((equal msg &quot;-----END PGP MESSAGE-----&quot;)
-      (message-over nick))
-     ((member nick *gpg-nicks-sending-messages*)
-      (add-line nick msg)))))
-
-(add-hook 'erc-server-PRIVMSG-functions 'gpg-process)
-
-(provide 'erc-gpg)
+    (when (string-match &quot;\\(.+\\): PGP MESSAGE \\(.+\\)&quot; msg)
+      (when (equal (erc-current-nick) (match-string 1 msg))
+        (print (decrypt (get-url-contents (match-string 2 msg))))))))
+
+(add-hook 'erc-server-PRIVMSG-functions 'listen-for-gpg-message)
+
+
+(setf *gpg-pastebin-function* 'paste-to-dpaste)
+(defun encrypt-and-paste-string (str for-nick)
+  &quot;Encrypts and pastes the message, returns the url for the message&quot;
+  (apply *gpg-pastebin-function* `(,(encrypt str for-nick))))
+
+(defun paste-to-dpaste (str)
+  &quot;Pastes str to dpaste and returns the url to the raw paste&quot;
+  (let ((dpaste-url &quot;http://dpaste.com/api/v1/&quot;)
+        (url-max-redirections 10)
+        (url-request-method &quot;POST&quot;)
+        (url-request-data (make-query-string `((&quot;content&quot; . ,str)))))
+    (with-current-buffer (url-retrieve-synchronously dpaste-url)
+      (re-search-backward &quot;\\/\\([0-9]+\\)\\/plain\\/&quot;)
+      (format &quot;http://dpaste.com/%s/plain/&quot; (match-string 1)))))
+
+
+(defun make-query-string (params)
+  &quot;Returns a query string constructed from PARAMS, which should be
+a list with elements of the form (KEY . VALUE). KEY and VALUE
+should both be strings.&quot;
+  (mapconcat
+   (lambda (param)
+     (concat (url-hexify-string (car param)) &quot;=&quot;
+             (url-hexify-string (cdr param))))
+   params &quot;&amp;&quot;))
+
+(defun get-url-contents (url)
+  (let ((buffer (url-retrieve-synchronously url)))
+    (with-current-buffer buffer
+      (beginning-of-buffer)
+      (search-forward-regexp &quot;\n\n&quot;)
+      (delete-region (point-min) (point))
+      (buffer-string))))
+
+(provide 'erc-gpg)
\ No newline at end of file</diff>
      <filename>erc-gpg.el</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>8d9c10b6b72cbec7316d2c6424a176f4c65bbdad</id>
    </parent>
  </parents>
  <author>
    <name>Ben Duffield</name>
    <email>jebavarde@gmail.com</email>
  </author>
  <url>http://github.com/bavardage/erc-gpg/commit/5246307ec9a4e9e36c9307bdbeff82f24f79657c</url>
  <id>5246307ec9a4e9e36c9307bdbeff82f24f79657c</id>
  <committed-date>2009-10-01T13:43:48-07:00</committed-date>
  <authored-date>2009-10-01T13:43:48-07:00</authored-date>
  <message>monkey-huge refactor
i.e. rewrite.</message>
  <tree>fde82b3a3f432ce8eaae7e8bee9d5114c053fde4</tree>
  <committer>
    <name>Ben Duffield</name>
    <email>jebavarde@gmail.com</email>
  </committer>
</commit>
