comparison src/lspst.c @ 378:ad7b880ad3d1

Alfredo Esteban - add -l and -f options to lspst
author Carl Byington <carl@five-ten-sg.com>
date Thu, 07 Dec 2017 08:43:57 -0800
parents d1f930be4711
children 5c0ce43c7532
comparison
equal deleted inserted replaced
377:506e266f930d 378:ad7b880ad3d1
14 int32_t item_count; 14 int32_t item_count;
15 int32_t skip_count; 15 int32_t skip_count;
16 int32_t type; 16 int32_t type;
17 }; 17 };
18 18
19 struct options {
20 int long_format;
21 char *date_format;
22 };
19 23
20 void canonicalize_filename(char *fname); 24 void canonicalize_filename(char *fname);
21 void debug_print(char *fmt, ...); 25 void debug_print(char *fmt, ...);
22 void usage(char *prog_name); 26 void usage(char *prog_name);
23 void version(); 27 void version();
40 void close_enter_dir(struct file_ll *f) 44 void close_enter_dir(struct file_ll *f)
41 { 45 {
42 free(f->dname); 46 free(f->dname);
43 } 47 }
44 48
45 49 void process(pst_item *outeritem, pst_desc_tree *d_ptr, struct options o)
46 void process(pst_item *outeritem, pst_desc_tree *d_ptr)
47 { 50 {
48 struct file_ll ff; 51 struct file_ll ff;
49 pst_item *item = NULL; 52 pst_item *item = NULL;
50 char *result = NULL; 53 char *result = NULL;
51 size_t resultlen = 0; 54 size_t resultlen = 0;
55 size_t dateresultlen;
52 56
53 DEBUG_ENT("process"); 57 DEBUG_ENT("process");
54 memset(&ff, 0, sizeof(ff)); 58 memset(&ff, 0, sizeof(ff));
55 create_enter_dir(&ff, outeritem); 59 create_enter_dir(&ff, outeritem);
56 60
72 76
73 if (item->folder && d_ptr->child) { 77 if (item->folder && d_ptr->child) {
74 // if this is a folder, we want to recurse into it 78 // if this is a folder, we want to recurse into it
75 pst_convert_utf8(item, &item->file_as); 79 pst_convert_utf8(item, &item->file_as);
76 printf("Folder \"%s\"\n", item->file_as.str); 80 printf("Folder \"%s\"\n", item->file_as.str);
77 process(item, d_ptr->child); 81 process(item, d_ptr->child, o);
78 82
79 } else if (item->contact && (item->type == PST_TYPE_CONTACT)) { 83 } else if (item->contact && (item->type == PST_TYPE_CONTACT)) {
80 if (!ff.type) ff.type = item->type; 84 if (!ff.type) ff.type = item->type;
81 // Process Contact item 85 // Process Contact item
82 if (ff.type != PST_TYPE_CONTACT) { 86 if (ff.type != PST_TYPE_CONTACT) {
92 // Process Email item 96 // Process Email item
93 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_SCHEDULE) && (ff.type != PST_TYPE_REPORT)) { 97 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_SCHEDULE) && (ff.type != PST_TYPE_REPORT)) {
94 DEBUG_INFO(("I have an email, but the folder isn't an email folder. Processing anyway\n")); 98 DEBUG_INFO(("I have an email, but the folder isn't an email folder. Processing anyway\n"));
95 } 99 }
96 printf("Email"); 100 printf("Email");
101 if (o.long_format == 1) {
102 if (item->email->arrival_date) {
103 char time_buffer[MAXDATEFMTLEN];
104 dateresultlen = pst_fileTimeToString(item->email->arrival_date, o.date_format, time_buffer);
105 if (dateresultlen < 1)
106 DIE(("Date format error in -f option.\n"));
107 printf("\tDate: %s", time_buffer);
108 }
109 else
110 printf("\t");
111 }
97 if (item->email->outlook_sender_name.str) 112 if (item->email->outlook_sender_name.str)
98 printf("\tFrom: %s", item->email->outlook_sender_name.str); 113 printf("\tFrom: %s", item->email->outlook_sender_name.str);
114 else
115 printf("\t");
116 if (o.long_format == 1) {
117 if (item->email->outlook_recipient_name.str)
118 printf("\tTo: %s", item->email->outlook_recipient_name.str);
119 else
120 printf("\t");
121 if (item->email->cc_address.str)
122 printf("\tCC: %s", item->email->cc_address.str);
123 else
124 printf("\t");
125 if (item->email->bcc_address.str)
126 printf("\tBCC: %s", item->email->bcc_address.str);
127 else
128 printf("\t");
129 }
99 if (item->subject.str) 130 if (item->subject.str)
100 printf("\tSubject: %s", item->subject.str); 131 printf("\tSubject: %s", item->subject.str);
132 else
133 printf("\t");
101 printf("\n"); 134 printf("\n");
102 135
103 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) { 136 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) {
104 if (!ff.type) ff.type = item->type; 137 if (!ff.type) ff.type = item->type;
105 // Process Journal item 138 // Process Journal item
150 DEBUG_ENT("usage"); 183 DEBUG_ENT("usage");
151 version(); 184 version();
152 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name); 185 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name);
153 printf("OPTIONS:\n"); 186 printf("OPTIONS:\n");
154 printf("\t-d <filename> \t- Debug to file. This is a binary log. Use readlog to print it\n"); 187 printf("\t-d <filename> \t- Debug to file. This is a binary log. Use readlog to print it\n");
188 printf("\t-l\t- Print the date, CC and BCC fields of emails too (by default only the From and Subject)\n");
189 printf("\t-f <date_format> \t- Select the date format in ctime format (by default \"%%F %%T\")\n");
155 printf("\t-h\t- Help. This screen\n"); 190 printf("\t-h\t- Help. This screen\n");
156 printf("\t-V\t- Version. Display program version\n"); 191 printf("\t-V\t- Version. Display program version\n");
157 DEBUG_RET(); 192 DEBUG_RET();
158 } 193 }
159 194
176 pst_item *item = NULL; 211 pst_item *item = NULL;
177 pst_desc_tree *d_ptr; 212 pst_desc_tree *d_ptr;
178 char *temp = NULL; //temporary char pointer 213 char *temp = NULL; //temporary char pointer
179 int c; 214 int c;
180 char *d_log = NULL; 215 char *d_log = NULL;
181 216 struct options o;
182 while ((c = getopt(argc, argv, "d:hV"))!= -1) { 217 o.long_format = 0;
218 char *defaultfmtdate = "%F %T";
219 o.date_format = defaultfmtdate;
220
221 while ((c = getopt(argc, argv, "d:f:lhV"))!= -1) {
183 switch (c) { 222 switch (c) {
184 case 'd': 223 case 'd':
185 d_log = optarg; 224 d_log = optarg;
225 break;
226 case 'f':
227 o.date_format = optarg;
228 break;
229 case 'l':
230 o.long_format = 1;
186 break; 231 break;
187 case 'h': 232 case 'h':
188 usage(argv[0]); 233 usage(argv[0]);
189 exit(0); 234 exit(0);
190 break; 235 break;
240 } 285 }
241 286
242 d_ptr = pst_getTopOfFolders(&pstfile, item); 287 d_ptr = pst_getTopOfFolders(&pstfile, item);
243 if (!d_ptr) DIE(("Top of folders record not found. Cannot continue\n")); 288 if (!d_ptr) DIE(("Top of folders record not found. Cannot continue\n"));
244 289
245 process(item, d_ptr->child); // do the childred of TOPF 290 process(item, d_ptr->child, o); // do the childred of TOPF
246 pst_freeItem(item); 291 pst_freeItem(item);
247 pst_close(&pstfile); 292 pst_close(&pstfile);
248 293
249 DEBUG_RET(); 294 DEBUG_RET();
250 return 0; 295 return 0;