[Libpst-devel] Re: PATCH: MH folder format
Arne Ahrend
aahrend at web.de
Sun Feb 19 19:49:48 UTC 2006
This patch (applied on top of the other seven)
- adds a -M option to produce MH output (MODE_SEPARATE with inline attachments)
- removes leading zeros, in numbered filenames
- starts file name numbering with one instead of zero
Arne
--- readpst.c-07 2006-02-19 20:04:49.000000000 +0100
+++ readpst.c 2006-02-19 20:19:56.000000000 +0100
@@ -42,6 +42,7 @@
#define OUTPUT_TEMPLATE "%s"
#define OUTPUT_KMAIL_DIR_TEMPLATE ".%s.directory"
#define KMAIL_INDEX ".%s.index"
+#define SEP_MAIL_FILE_TEMPLATE "%i" /* "%09i" */
#define VERSION "0.5.1"
// max size of the c_time char*. It will store the date of the email
@@ -90,7 +91,7 @@ void write_separate_attachment(char f_na
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);
-void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, pst_file* pst);
+void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, int mode_MH, pst_file* pst);
void create_enter_dir(struct file_ll* f, char file_as[], int mode, int overwrite);
void write_vcard(FILE* f_output, pst_item_contact* contact, char comment[]);
void write_appointment(FILE* f_output, pst_item_appointment* appointment, pst_item_email* email,
@@ -146,6 +147,7 @@ int main(int argc, char** argv) {
char *d_log=NULL;
int c,x;
int mode = MODE_NORMAL;
+ int mode_MH = 0;
int output_mode = OUTPUT_NORMAL;
int contact_mode = CMODE_VCARD;
int overwrite = 0;
@@ -156,7 +158,7 @@ int main(int argc, char** argv) {
prog_name = argv[0];
// }}}2
- while ((c = getopt(argc, argv, "d:hko:qrSVwc:"))!= -1) {
+ while ((c = getopt(argc, argv, "d:hko:qrMSVwc:"))!= -1) {
switch (c) {
case 'c':
if (optarg!=NULL && optarg[0]=='v')
@@ -182,6 +184,10 @@ int main(int argc, char** argv) {
case 'k':
mode = MODE_KMAIL;
break;
+ case 'M':
+ mode = MODE_SEPERATE;
+ mode_MH = 1;
+ break;
case 'o':
output_dir = optarg;
break;
@@ -394,7 +400,7 @@ int main(int argc, char** argv) {
f->email_count++;
DEBUG_MAIN(("main: seen an email\n"));
- write_normal_email(f->output, f->name, item, mode, &pstfile);
+ write_normal_email(f->output, f->name, item, mode, mode_MH, &pstfile);
} else if (item->type == PST_TYPE_JOURNAL) {
// Process Journal item {{{2
// deal with journal items
@@ -566,6 +572,7 @@ int usage() {
printf("\t-d\t- Debug to file. This is a binary log. Use readlog to print it\n");
printf("\t-h\t- Help. This screen\n");
printf("\t-k\t- KMail. Output in kmail format\n");
+ printf("\t-M\t- MH. Write emails in the MH format\n");
printf("\t-o\t- Output Dir. Directory to write files to. CWD is changed *after* opening pst file\n");
printf("\t-q\t- Quiet. Only print error messages\n");
printf("\t-r\t- Recursive. Output in a recursive format\n");
@@ -709,7 +716,7 @@ char *mk_seperate_dir(char *dir, int ove
if (y == 0)
sprintf(dir_name, "%s", dir);
else
- sprintf(dir_name, "%s%09i", dir, y); // enough for 9 digits allocated above
+ sprintf(dir_name, "%s" SEP_MAIL_FILE_TEMPLATE, dir, y); // enough for 9 digits allocated above
dir_name = check_filename(dir_name);
DEBUG_MAIN(("mk_seperate_dir: about to try creating %s\n", dir_name));
@@ -770,12 +777,13 @@ int close_seperate_dir() {
// }}}1
// int mk_seperate_file(struct file_ll *f) {{{1
int mk_seperate_file(struct file_ll *f) {
+ const int name_offset = 1;
DEBUG_ENT("mk_seperate_file");
DEBUG_MAIN(("mk_seperate_file: opening next file to save email\n"));
if (f->email_count > 999999999) { // bigger than nine 9's
DIE(("mk_seperate_file: The number of emails in this folder has become too high to handle"));
}
- sprintf(f->name, "%09i", f->email_count);
+ sprintf(f->name, SEP_MAIL_FILE_TEMPLATE, f->email_count + name_offset);
if (f->output != NULL)
fclose(f->output);
f->output = NULL;
@@ -1055,7 +1063,7 @@ void write_fabricated_header(FILE* f_out
fprintf(f_output, "\n");
}
-void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, pst_file* pst)
+void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, int mode_MH, pst_file* pst)
{
char *boundary = NULL; // the boundary marker between multipart sections
char *c_time;
@@ -1260,13 +1268,13 @@ void write_normal_email(FILE* f_output,
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));
}
- if (mode == MODE_SEPERATE)
+ attach_num++;
+ if (mode == MODE_SEPERATE && !mode_MH)
write_separate_attachment(f_name, item->current_attach, attach_num, pst);
else
write_inline_attachment(f_output, item->current_attach, boundary, pst);
- attach_num++;
}
- if (mode != MODE_SEPERATE) {
+ if (mode != MODE_SEPERATE) { /* do not add a boundary after the last attachment for mode_MH */
DEBUG_MAIN(("main: Writing buffer between emails\n"));
if (boundary)
fprintf(f_output, "\n--%s--\n", boundary);
@@ -1289,7 +1297,7 @@ void create_enter_dir(struct file_ll* f,
mk_seperate_dir(file_as, overwrite);
f->name = (char*) xmalloc(10);
memset(f->name, 0, 10);
- // sprintf(f->name, "%09i", f->email_count);
+ // sprintf(f->name, SEP_MAIL_FILE_TEMPLATE, f->email_count);
} else {
f->name = (char*) xmalloc(strlen(file_as)+strlen(OUTPUT_TEMPLATE+1));
sprintf(f->name, OUTPUT_TEMPLATE, file_as);
More information about the Libpst-devel
mailing list