On Sat, Feb 2, 2013 at 6:40 PM, Roland Winkler <wink...@gnu.org> wrote:


> Following recent discussions with Sriram on this list, the patch
> below tries to avoid more carefully that text properties
> accidentally enter BBDB.
>

Great! I am not familiar with BBDB internals enough to understand the full
patch, but I assume you mean any MUA action is guaranteed not to introduce
any text properties into the db?


> If users have their own code to feed BBDB, it is, however, their
> responsibility to ensure that text properties do not accidentally
> enter BBDB.
>

I was working on a configuration variable based low-level control to filter
out stuff. The attached patch tries to do that by fixing the bbdb-defstruct
macro. Do you think it will work for all cases?

As the above approach does not fix existing records, the patch also has an
interactive function to purge existing databases of text properties. I am
having difficulties getting it to work. I think I am stuck. Basically I am
not sure how to parse an entire record looking for strings and to
reconstruct a 'fixed' record vector in-place. Can you help fix this routine
that will be directly useful for users having this issue now?

diff --git a/lisp/bbdb.el b/lisp/bbdb.el
index be81580..4fd87d7 100644
--- a/lisp/bbdb.el
+++ b/lisp/bbdb.el
@@ -278,6 +278,15 @@ Lisp Hackers: See also `bbdb-silent-internal'."
   :type '(choice (const :tag "Standard location" nil)
                  (file :tag "Nonstandard location")))

+(defcustom bbdb-preserve-text-properties nil
+  "If nil, bbdb will purge text properties before writing to database. If t
+any BBDB will not cleanse the strings, and all properties it receives from
+MUAs, and other input sources are retained and written to the database in
the
+#(...) elisp vector notation."
+  :group 'bbdb
+  :type '(choice (const :tag "Allow text properties in BBDB database" t)
+                 (const :tag "Text properties not written to BBDB
database" nil)))
+

 ;;; Record display

@@ -1919,6 +1928,30 @@ Used with return values of `bbdb-add-job'."
       (and (eq spec 'query)
            (or bbdb-silent (y-or-n-p prompt)))))

+(defun bbdb-strip-properties (value)
+  "If value is of type string remove all text properties from it and return
+the plain string. If value is of type list, do the property stripping for
all
+contained strings. If value is of any other type return it as it is."
+  (cond ((stringp value)
+ (progn
+   (set-text-properties 0 (length value) nil value)
+   value))
+ ((consp value)
+ (cons (bbdb-strip-properties (car value))
+       (bbdb-strip-properties (cdr value))))
+ ((or (listp value)
+ (mapcar 'bbdb-strip-properties value))
+ (t value)))
+
+(defun bbdb-purge-text-properties ()
+  "Purge all the text properties in all strings in the BBDB database."
+
+  (interactive)
+  (setq bbdb-records
+ (mapcar 'bbdb-strip-properties bbdb-records))
+  (dolist (record bbdb-records)
+    (bbdb-overwrite-record-internal record)))
+
 ;; BBDB data structure
 (defmacro bbdb-defstruct (name &rest elts)
   "Define two functions to operate on vector NAME for each symbol ELT in
ELTS.
@@ -1949,7 +1982,10 @@ which ensures the integrity of the database.  Also,
this makes your code
 more robust with respect to possible future changes of BBDB's innermost
 internals."
                             uname count selt)
-                    `(aset ,name ,count value)) body))
+                    `(aset ,name ,count
+   (if bbdb-preserve-text-properties
+       value
+     (bbdb-strip-properties value)))) body))
       (setq count (1+ count)))
     (push (list 'defconst (intern (concat cname "length")) count
                 (concat "Length of BBDB `" sname "'.")) body)
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_jan
_______________________________________________
bbdb-info@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/bbdb-info
BBDB Home Page: http://bbdb.sourceforge.net/

Reply via email to