 (defn parse-message
   "Parse a Portal message."
   [message]
-  (let [message (second (.split (apply str (butlast (str message)))":"))
-        [id type content] (.split message " ")]
+  (let [message (second (split (string/join (butlast (str message))) #":" 2))
+        [id type content] (split message #" " 3)]
+    (prn "message:" message)
     {:type (keyword type)
      :id id
-     :content content}))
+     :content (string/join " " content)}))
 
 (defn send-message
   "Send a portal message."

(defn context
  "Look up a context. If no context exists, create one."
  [id]
  (or (@contexts id)
      (get
       (swap! contexts assoc id
              {:results []
               :count 0
               :stdout []
               :stderr []})
       id)))

(defn update-context
  "Update a context."
  [id key f & args]
  (context id)
  (swap! contexts update-in [id key] (fn [old] (apply f old args))))

(defn netstring
  "Create a netstring."


(defn eval
  "Evaluate code."
  ([sock form callback] (eval sock form (rand-int 9999999999999999) callback))
  ([sock form id callback]
     (send-message sock id "eval" form)
     (update-context id :callbacks assoc
                     (update-context id :eval inc)
                     callback)))

(defn tail
  "Tail stdout or stderr from a context."
