[Nym3-commit] r10 - trunk

nym3-devel@lists.noreply.org nym3-devel@lists.noreply.org
Sun, 02 May 2004 18:43:50 +0200


Author: laurent
Date: 2004-05-02 18:43:49 +0200 (Sun, 02 May 2004)
New Revision: 10

Added:
   trunk/synopsis.ml
Log:
Started working on synopsis.


Added: trunk/synopsis.ml
===================================================================
--- trunk/synopsis.ml	2004-04-29 19:41:27 UTC (rev 9)
+++ trunk/synopsis.ml	2004-05-02 16:43:49 UTC (rev 10)
@@ -0,0 +1,57 @@
+
+(* Grep the relevant headers and cut at 80 chars *)
+let synopsize_headers headers =
+	let good_headers = [ "Cc"; "From"; "Date"; "Subject";
+						 "In-Reply-To"; "Message-Id"; "To";
+						 "References"; "Return-Path"; "Sender";
+						 "X-Anonymous"; "X-Spam-Level" ] in
+	let rec aux x = match x with
+		| [] -> ""
+		| [a] -> "\\(^" ^ a ^ ":.*\\)"
+		| a::b -> "\\(^" ^ a ^ ":.*\\)\\|" ^ (aux b)
+	in
+	let headerre = aux good_headers in
+	let rec unfold l = match l with
+		| [] -> []
+		| [a] -> [a]
+		| a::b::q -> 
+		  if Str.string_match (Str.regexp "^\\(\t\\| \\)+\\(.*\\)$") b 0 
+		  then unfold ((a ^ " " ^ (Str.matched_group 2 b))::q)
+		  else a::(unfold (b::q))
+	in
+	let rec grep limit re l = match l with
+		| [] -> []
+		| a::b -> if Str.string_partial_match re a 0 then 
+			let la = 
+				if String.length a > limit then
+					Str.first_chars a limit
+				else
+					a
+			in
+			la::(grep limit re b) else
+				  grep limit re b
+	in
+	grep 80 (Str.regexp headerre) (unfold headers);;
+
+
+(* Uncomment to test
+
+let l = ref [];;
+
+try
+	while true do
+		l := (read_line ()) :: !l;
+	done
+with
+	_ -> ();;
+
+l := List.rev !l;
+
+let res = ref (synopsize_headers !l) in
+	while !res != [] do
+		print_string "Debut de header\n";
+		print_string (List.hd !res);
+		print_string "\nFin de header\n";
+		res := List.tl !res;
+	done;;
+*)