evolution-data-server r8667 - branches/gnome-2-22/camel



Author: psankar
Date: Mon Apr 21 04:49:00 2008
New Revision: 8667
URL: http://svn.gnome.org/viewvc/evolution-data-server?rev=8667&view=rev

Log:
2008-04-21  Sankar P  <psankar novell com>

	* camel-mime-filter-pgp.c: (filter_run):
	Patch to improve PGP parsing. Taken from Trunk.
	Thanks to Fejj for his review, work and help.




Modified:
   branches/gnome-2-22/camel/ChangeLog
   branches/gnome-2-22/camel/camel-mime-filter-pgp.c

Modified: branches/gnome-2-22/camel/camel-mime-filter-pgp.c
==============================================================================
--- branches/gnome-2-22/camel/camel-mime-filter-pgp.c	(original)
+++ branches/gnome-2-22/camel/camel-mime-filter-pgp.c	Mon Apr 21 04:49:00 2008
@@ -79,25 +79,35 @@
 #define BEGIN_PGP_SIGNATURE      "-----BEGIN PGP SIGNATURE-----"
 #define END_PGP_SIGNATURE        "-----END PGP SIGNATURE-----"
 
+#define BEGIN_PGP_SIGNED_MESSAGE_LEN (sizeof (BEGIN_PGP_SIGNED_MESSAGE) - 1)
+#define BEGIN_PGP_SIGNATURE_LEN      (sizeof (BEGIN_PGP_SIGNATURE) - 1)
+#define END_PGP_SIGNATURE_LEN        (sizeof (END_PGP_SIGNATURE) - 1)
+
 static void
-filter_run(CamelMimeFilter *f, char *in, size_t len, size_t prespace, char **out, size_t *outlen, size_t *outprespace, int last)
+filter_run(CamelMimeFilter *f, char *in, size_t inlen, size_t prespace, char **out, size_t *outlen, size_t *outprespace, int last)
 {
 	CamelMimeFilterPgp *pgp = (CamelMimeFilterPgp *) f;
-	const char *start, *inend = in + len;
+	const char *start, *inend = in + inlen;
 	register const char *inptr = in;
 	register char *o;
-
+	gboolean blank;
+	size_t len;
+	
 	/* only need as much space as the input, we're stripping chars */
-	camel_mime_filter_set_size (f, len, FALSE);
-
+	camel_mime_filter_set_size (f, inlen, FALSE);
+	
 	o = f->outbuf;
-
+	
 	while (inptr < inend) {
 		start = inptr;
-
-		while (inptr < inend && *inptr != '\n')
+		
+		blank = TRUE;
+		while (inptr < inend && *inptr != '\n') {
+			if (blank && !strchr (" \t\r", *inptr))
+				blank = FALSE;
 			inptr++;
-
+		}
+		
 		if (inptr == inend) {
 			if (!last) {
 				camel_mime_filter_backup (f, start, inend - start);
@@ -105,49 +115,53 @@
 			}
 			break;
 		}
-
+		
+		len = inptr - start;
+		if (len > 0 && inptr[-1] == '\r')
+			len--;
+		
 		inptr++;
-
+		
 		switch (pgp->state) {
 		case PGP_PREFACE:
 			/* check for the beginning of the pgp block */
-			if (!strncmp (start, BEGIN_PGP_SIGNED_MESSAGE, sizeof (BEGIN_PGP_SIGNED_MESSAGE) - 1)) {
+			if (len == BEGIN_PGP_SIGNED_MESSAGE_LEN && !strncmp (start, BEGIN_PGP_SIGNED_MESSAGE, len)) {
 				pgp->state++;
 				break;
 			}
-
+			
 			memcpy (o, start, inptr - start);
 			o += (inptr - start);
 			break;
 		case PGP_HEADER:
 			/* pgp headers (Hash: SHA1, etc) end with a blank (zero-length,
 			   or containing only whitespace) line; see RFC2440 */
-			if ((inptr - start) == 1 || ((inptr - start) == 2 && *(inptr - 2) == 0x20))
+			if (blank)
 				pgp->state++;
 			break;
 		case PGP_MESSAGE:
 			/* check for beginning of the pgp signature block */
-			if (!strncmp (start, BEGIN_PGP_SIGNATURE, sizeof (BEGIN_PGP_SIGNATURE) - 1)) {
+			if (len == BEGIN_PGP_SIGNATURE_LEN && !strncmp (start, BEGIN_PGP_SIGNATURE, len)) {
 				pgp->state++;
 				break;
 			}
-
+			
 			/* do dash decoding */
 			if (!strncmp (start, "- ", 2)) {
 				/* Dash encoded line found, skip encoding */
 				start += 2;
 			}
-
+			
 			memcpy (o, start, inptr - start);
 			o += (inptr - start);
 			break;
 		case PGP_FOOTER:
-			if (!strncmp (start, END_PGP_SIGNATURE, sizeof (END_PGP_SIGNATURE) - 1))
+			if (len == END_PGP_SIGNATURE_LEN && !strncmp (start, END_PGP_SIGNATURE, len))
 				pgp->state = PGP_PREFACE;
 			break;
 		}
 	}
-
+	
 	*out = f->outbuf;
 	*outlen = o - f->outbuf;
 	*outprespace = f->outpre;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]