[Libpst-devel] Re: PATCH: readpst.c code reorganisation
Arne Ahrend
aahrend at web.de
Sun Feb 19 19:35:41 UTC 2006
On Sun, 19 Feb 2006 20:33:56 +0100
Arne Ahrend <aahrend at web.de> wrote:
second 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-01 2006-02-19 19:21:39.000000000 +0100
+++ readpst.c 2006-02-19 19:22:13.000000000 +0100
@@ -87,6 +87,7 @@ char *rfc2425_datetime_format(FILETIME *
char *rfc2445_datetime_format(FILETIME *ft);
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);
// }}}1
// Global Variables {{{1
char *prog_name;
@@ -144,7 +145,6 @@ int main(int argc, char** argv) {
int overwrite = 0;
int base64_body = 0;
// int encrypt = 0;
- char *enc; // base64 encoded attachment
char *boundary = NULL, *b1, *b2; // the boundary marker between multipart sections
char *temp = NULL; //temporary char pointer
int attach_num = 0;
@@ -825,8 +825,9 @@ int main(int argc, char** argv) {
}
base64_body = 0;
// attachments
- item->current_attach = item->attach;
- while (item->current_attach != NULL) {
+ for(item->current_attach = item->attach;
+ item->current_attach;
+ item->current_attach = item->current_attach->next) {
DEBUG_MAIN(("main: Attempting Attachment encoding\n"));
if (item->current_attach->data == NULL) {
DEBUG_MAIN(("main: Data of attachment is NULL!. Size is supposed to be %i\n", item->current_attach->size));
@@ -834,39 +835,8 @@ int main(int argc, char** argv) {
if (mode == MODE_SEPERATE) {
write_separate_attachment(f->name, item->current_attach, attach_num, &pstfile);
} else {
- DEBUG_MAIN(("main: Attachment Size is %i\n", item->current_attach->size));
- DEBUG_MAIN(("main: Attachment Pointer is %p\n", item->current_attach->data));
- if (item->current_attach->data != NULL) {
- if ((enc = base64_encode (item->current_attach->data, item->current_attach->size)) == NULL) {
- DEBUG_MAIN(("main: ERROR base64_encode returned NULL. Must have failed\n"));
- item->current_attach = item->current_attach->next;
- continue;
- }
- }
- if (boundary) {
- fprintf(f->output, "\n--%s\n", boundary);
- if (item->current_attach->mimetype == NULL) {
- fprintf(f->output, "Content-type: %s\n", MIME_TYPE_DEFAULT);
- } else {
- fprintf(f->output, "Content-type: %s\n", item->current_attach->mimetype);
- }
- fprintf(f->output, "Content-transfer-encoding: base64\n");
- if (item->current_attach->filename2 == NULL) {
- fprintf(f->output, "Content-Disposition: inline\n\n");
- } else {
- fprintf(f->output, "Content-Disposition: attachment; filename=\"%s\"\n\n",
- item->current_attach->filename2);
- }
- }
- if (item->current_attach->data != NULL) {
- fwrite(enc, 1, strlen(enc), f->output);
- DEBUG_MAIN(("Attachment Size after encoding is %i\n", strlen(enc)));
- } else {
- pst_attach_to_file_base64(&pstfile, item->current_attach, f->output);
- }
- fprintf(f->output, "\n\n");
+ write_inline_attachment(f->output, item->current_attach, boundary, &pstfile);
}
- item->current_attach = item->current_attach->next;
attach_num++;
}
if (mode != MODE_SEPERATE) {
@@ -1481,7 +1451,6 @@ void write_separate_attachment(char f_na
FILE *fp = NULL;
char *temp = NULL;
int x = 0;
-
check_filename(f_name);
if (current_attach->filename2 == NULL) {
temp = xmalloc(strlen(f_name)+15);
@@ -1511,3 +1480,38 @@ void write_separate_attachment(char f_na
fclose(fp);
}
}
+
+void write_inline_attachment(FILE* f_output, pst_item_attach* current_attach, char boundary[], pst_file* pst)
+{
+ char *enc; // base64 encoded attachment
+ DEBUG_MAIN(("write_inline_attachment: Attachment Size is %i\n", current_attach->size));
+ DEBUG_MAIN(("write_inline_attachment: Attachment Pointer is %p\n", current_attach->data));
+ if (current_attach->data != NULL) {
+ if ((enc = base64_encode (current_attach->data, current_attach->size)) == NULL) {
+ DEBUG_MAIN(("write_inline_attachment: ERROR base64_encode returned NULL. Must have failed\n"));
+ return;
+ }
+ }
+ if (boundary) {
+ fprintf(f_output, "\n--%s\n", boundary);
+ if (current_attach->mimetype == NULL) {
+ fprintf(f_output, "Content-type: %s\n", MIME_TYPE_DEFAULT);
+ } else {
+ fprintf(f_output, "Content-type: %s\n", current_attach->mimetype);
+ }
+ fprintf(f_output, "Content-transfer-encoding: base64\n");
+ if (current_attach->filename2 == NULL) {
+ fprintf(f_output, "Content-Disposition: inline\n\n");
+ } else {
+ fprintf(f_output, "Content-Disposition: attachment; filename=\"%s\"\n\n",
+ current_attach->filename2);
+ }
+ }
+ if (current_attach->data != NULL) {
+ fwrite(enc, 1, strlen(enc), f_output);
+ DEBUG_MAIN(("write_inline_attachment: Attachment Size after encoding is %i\n", strlen(enc)));
+ } else {
+ pst_attach_to_file_base64(pst, current_attach, f_output);
+ }
+ fprintf(f_output, "\n\n");
+}
More information about the Libpst-devel
mailing list