[Libpst-devel] Re: PATCH: readpst.c code reorganisation

Arne Ahrend aahrend at web.de
Sun Feb 19 19:36:53 UTC 2006


On Sun, 19 Feb 2006 20:33:56 +0100
Arne Ahrend <aahrend at web.de> wrote:

Third patch

> This is a series of patches succesively taking chunks of code out of 
> the huge main() function in readpst.c and into separate functions.
> 
> No functionality change, but improvement of readability.
> 
> Arne

--- readpst.c-02	2006-02-19 19:22:13.000000000 +0100
+++ readpst.c	2006-02-19 19:22:54.000000000 +0100
@@ -88,6 +88,8 @@ char *rfc2445_datetime_format(FILETIME *
 char *skip_header_prologue(char *headers);
 void write_separate_attachment(char f_name[], pst_item_attach* current_attach, int attach_num, pst_file* pst);
 void write_inline_attachment(FILE* f_output, pst_item_attach* current_attach, char boundary[], pst_file* pst);
+void write_fabricated_header(FILE* f_output, pst_item_email* email, pst_item_attach* attach,
+			     char boundary[], int mode, char c_time[], time_t em_time);
 // }}}1
 // Global Variables {{{1
 char *prog_name; 
@@ -701,50 +703,8 @@ int main(int argc, char** argv) {
 	  } else {
 	    fprintf(f->output, "%s\n", item->email->header);
 	  }
-	} else {
-	  //make up our own header!
-	  if (mode != MODE_SEPERATE) {
-	    // don't want this first line for this mode
-	    if (item->email->outlook_sender_name != NULL) {
-	      temp = item->email->outlook_sender_name;
-	    } else {
-	      temp = "(readpst_null)";
-	    }
-	    fprintf(f->output, "From \"%s\" %s\n", temp, c_time);
-	  }
-	  if ((temp = item->email->outlook_sender) == NULL)
-	    temp = "";
-	  fprintf(f->output, "From: \"%s\" <%s>\n", item->email->outlook_sender_name, temp);
-	  if (item->email->subject != NULL) {
-	    fprintf(f->output, "Subject: %s\n", item->email->subject->subj);
-	  } else {
-	    fprintf(f->output, "Subject: \n");
-	  }
-	  fprintf(f->output, "To: %s\n", item->email->sentto_address);
-	  if (item->email->cc_address != NULL) {
-	    fprintf(f->output, "CC: %s\n", item->email->cc_address);
-	  }
-	  if (item->email->sent_date != NULL) {
-	    c_time = (char*) xmalloc(C_TIME_SIZE);
-	    strftime(c_time, C_TIME_SIZE, "%a, %d %b %Y %H:%M:%S %z", gmtime(&em_time));
-	    fprintf(f->output, "Date: %s\n", c_time);
-	    free(c_time);
-	  }
-
-	  fprintf(f->output, "MIME-Version: 1.0\n");
-	  if (item->attach != NULL) {
-	    // write the boundary stuff if we have attachments
-	    fprintf(f->output, "Content-type: multipart/mixed;\n\tboundary=\"%s\"\n",
-		    boundary);
-	  } else if (item->email->htmlbody && item->email->body) {
-	    // else if we have an html and text body then tell it so
-	    fprintf(f->output, "Content-type: multipart/alternate;\n\tboundary=\"%s\"\n",
-		    boundary);
-	  } else if (item->email->htmlbody) {
-	    fprintf(f->output, "Content-type: text/html\n");
-	  }
-	  fprintf(f->output, "\n");
-	}
+	} else
+	  write_fabricated_header(f->output, item->email, item->attach, boundary, mode, c_time, em_time);
 	
 
 	DEBUG_MAIN(("main: About to print Body\n"));
@@ -1515,3 +1475,52 @@ void write_inline_attachment(FILE* f_out
 	}
 	fprintf(f_output, "\n\n");
 }
+
+void write_fabricated_header(FILE* f_output, pst_item_email* email, pst_item_attach* attach,
+			     char boundary[], int mode, char c_time[], time_t em_time)
+{
+	char *temp = NULL;
+	//make up our own header!
+	if (mode != MODE_SEPERATE) {
+		// don't want this first line for this mode
+		if (email->outlook_sender_name != NULL) {
+			temp = email->outlook_sender_name;
+		} else {
+			temp = "(readpst_null)";
+		}
+		fprintf(f_output, "From \"%s\" %s\n", temp, c_time);
+	}
+	if ((temp = email->outlook_sender) == NULL)
+		temp = "";
+	fprintf(f_output, "From: \"%s\" <%s>\n", email->outlook_sender_name, temp);
+	if (email->subject != NULL) {
+		fprintf(f_output, "Subject: %s\n", email->subject->subj);
+	} else {
+		fprintf(f_output, "Subject: \n");
+	}
+	fprintf(f_output, "To: %s\n", email->sentto_address);
+	if (email->cc_address != NULL) {
+		fprintf(f_output, "CC: %s\n", email->cc_address);
+	}
+	if (email->sent_date != NULL) {
+		c_time = (char*) xmalloc(C_TIME_SIZE);
+		strftime(c_time, C_TIME_SIZE, "%a, %d %b %Y %H:%M:%S %z", gmtime(&em_time));
+		fprintf(f_output, "Date: %s\n", c_time);
+		free(c_time);
+	}
+
+	fprintf(f_output, "MIME-Version: 1.0\n");
+	if (attach != NULL) {
+		// write the boundary stuff if we have attachments
+		fprintf(f_output, "Content-type: multipart/mixed;\n\tboundary=\"%s\"\n",
+			boundary);
+	} else if (email->htmlbody && email->body) {
+		// else if we have an html and text body then tell it so
+		fprintf(f_output, "Content-type: multipart/alternate;\n\tboundary=\"%s\"\n",
+			boundary);
+	} else if (email->htmlbody) {
+		fprintf(f_output, "Content-type: text/html\n");
+	}
+	fprintf(f_output, "\n");
+}
+



More information about the Libpst-devel mailing list