Impose size limits as per Livejournal API docs.
[slh] / lj.el
diff --git a/lj.el b/lj.el
index d05e0fa..37a0e6d 100644 (file)
--- a/lj.el
+++ b/lj.el
 ;;
 
 ;;; Version:
-(defconst lj-version 1.26
+(defconst lj-version 1.27
   "Version number of SXEmacs/LJ.")
 
 ;;; Code:
@@ -1743,8 +1743,9 @@ General bindings:
 \\{lj-mode-map}"
   :group 'lj
   :syntax-table nil
-  :abbrev-table 'lj-abbrev-table
-  (auto-save-mode 1))
+  :abbrev-table lj-abbrev-table
+  (auto-save-mode 1)
+  (abbrev-mode 1))
 
 (add-hook 'lj-mode-hook #'font-lock-mode)
 
@@ -2608,6 +2609,40 @@ Argument URL is the URL to the post on livejournal.com."
          (set-process-sentinel proc #'lj-twitter-sentinel))
       (warn "LJ subject too long for Twitter"))))
 
+(defun lj-check-limits (bodlen sublen taglen muslen loclen)
+  "Make sure we don't exceed any LJ size limits.
+
+Argument BODLEN: length of the body of a post.  Max is 65535 bytes.
+Argument SUBLEN: length of the subject header.  Max is 100 chars.
+Argument TAGLEN: length of the tags header.  Max is 100 chars.
+Argument MUSLEN: length of the music header.  Max is 100 chars.
+Argument LOCLEN: length of the location header.  Max is 100 chars."
+  (let ((maxbod 65535)
+       (maxsub 100)
+       (maxtag 100)
+       (maxmus 100)
+       (maxloc 100))
+    (and (> bodlen maxbod)
+        (error 'invalid-argument
+               (format "Post body exceeds maximum by %d chars"
+                       (- bodlen maxbod))))
+    (and (> sublen maxsub)
+        (error 'invalid-argument
+               (format "Subject exceeds maximum by %d chars"
+                       (- sublen maxsub))))
+    (and (> taglen maxtag)
+        (error 'invalid-argument
+               (format "Tags exceed maximum by %d chars"
+                       (- taglen maxtag))))
+    (and (> muslen maxmus)
+        (error 'invalid-argument
+               (format "Music header exceeds maximum by %d chars"
+                       (- muslen maxmus))))
+    (and (> loclen maxloc)
+        (error 'invalid-argument
+               (format "Location header exceeds maximum by %d chars"
+                       (- loclen maxloc))))))
+
 (defun lj-post (&optional out-of-order)
   "Submit a new post to LiveJournal.
 
@@ -2647,6 +2682,11 @@ With two prefix args, also set a \"date out of order\" flag."
          ((eq (car current-prefix-arg) 16)
           (setq date (lj-set-date/time)
                 backdated t)))
+    (lj-check-limits (length body)
+                    (length subject)
+                    (length tags)
+                    (length music)
+                    (length location))
     (setq url (lj-construct-url subject body user security tags comm nil nil
                                mood location music pickw date backdated))
     ;; lets save the draft out to disc just in case something goes wrong