changeset 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 506e266f930d
children bbd198da4033
files AUTHORS ChangeLog configure.in src/define.h src/lspst.c src/timeconv.c src/timeconv.h xml/libpst.in
diffstat 8 files changed, 88 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/AUTHORS	Mon Nov 20 08:19:28 2017 -0800
+++ b/AUTHORS	Thu Dec 07 08:43:57 2017 -0800
@@ -43,6 +43,7 @@
     Igor Stroh <igor.stroh@rulim.de>
     Zachary Travis <ztravis@everlaw.com>
     Vitaliy Didik <ariman@inbox.ru>
+    Alfredo Esteban <aedelatorre@gmail.com>
 
 Testing team:
     Mac OSX - Michael Watson <mike@mikeandgayle.com>
--- a/ChangeLog	Mon Nov 20 08:19:28 2017 -0800
+++ b/ChangeLog	Thu Dec 07 08:43:57 2017 -0800
@@ -1,3 +1,7 @@
+LibPST 0.6.72 (2017-12-07)
+===============================
+    * Alfredo Esteban - add -l and -f options to lspst.
+
 LibPST 0.6.71 (2017-07-21)
 ===============================
     * Zachary Travis - Add support for the OST 2013 format, and
--- a/configure.in	Mon Nov 20 08:19:28 2017 -0800
+++ b/configure.in	Thu Dec 07 08:43:57 2017 -0800
@@ -1,5 +1,5 @@
 AC_PREREQ(2.60)
-AC_INIT(libpst,0.6.71,carl@five-ten-sg.com)
+AC_INIT(libpst,0.6.72,carl@five-ten-sg.com)
 AC_CONFIG_SRCDIR([src/libpst.c])
 AC_CONFIG_HEADER([config.h])
 AC_CONFIG_MACRO_DIR([m4])
--- a/src/define.h	Mon Nov 20 08:19:28 2017 -0800
+++ b/src/define.h	Thu Dec 07 08:43:57 2017 -0800
@@ -256,5 +256,6 @@
 
 #define PST_LE_GET_INT8(p) (*(int8_t const *)(p))
 
+#define MAXDATEFMTLEN 40
 
 #endif //DEFINEH_H
--- a/src/lspst.c	Mon Nov 20 08:19:28 2017 -0800
+++ b/src/lspst.c	Thu Dec 07 08:43:57 2017 -0800
@@ -16,6 +16,10 @@
     int32_t type;
 };
 
+struct options {
+    int long_format;
+    char *date_format;
+};
 
 void canonicalize_filename(char *fname);
 void debug_print(char *fmt, ...);
@@ -42,13 +46,13 @@
     free(f->dname);
 }
 
-
-void process(pst_item *outeritem, pst_desc_tree *d_ptr)
+void process(pst_item *outeritem, pst_desc_tree *d_ptr, struct options o)
 {
     struct file_ll ff;
     pst_item *item = NULL;
     char *result = NULL;
     size_t resultlen = 0;
+    size_t dateresultlen;
 
     DEBUG_ENT("process");
     memset(&ff, 0, sizeof(ff));
@@ -74,7 +78,7 @@
                     // if this is a folder, we want to recurse into it
                     pst_convert_utf8(item, &item->file_as);
                     printf("Folder \"%s\"\n", item->file_as.str);
-                    process(item, d_ptr->child);
+                    process(item, d_ptr->child, o);
 
                 } else if (item->contact && (item->type == PST_TYPE_CONTACT)) {
                     if (!ff.type) ff.type = item->type;
@@ -94,10 +98,39 @@
                         DEBUG_INFO(("I have an email, but the folder isn't an email folder. Processing anyway\n"));
                     }
                     printf("Email");
+                    if (o.long_format == 1) {
+                        if (item->email->arrival_date) {
+                            char time_buffer[MAXDATEFMTLEN];
+                            dateresultlen = pst_fileTimeToString(item->email->arrival_date, o.date_format, time_buffer);
+                            if (dateresultlen < 1)
+                                DIE(("Date format error in -f option.\n"));
+                            printf("\tDate: %s", time_buffer);
+                        }
+                        else
+                            printf("\t");
+                    }
                     if (item->email->outlook_sender_name.str)
                         printf("\tFrom: %s", item->email->outlook_sender_name.str);
+                    else
+                        printf("\t");
+                    if (o.long_format == 1) {
+                        if (item->email->outlook_recipient_name.str)
+                            printf("\tTo: %s", item->email->outlook_recipient_name.str);
+                        else
+                            printf("\t");
+                        if (item->email->cc_address.str)
+                            printf("\tCC: %s", item->email->cc_address.str);
+                        else
+                            printf("\t");
+                        if (item->email->bcc_address.str)
+                            printf("\tBCC: %s", item->email->bcc_address.str);
+                        else
+                            printf("\t");
+                    }
                     if (item->subject.str)
                         printf("\tSubject: %s", item->subject.str);
+                    else
+                        printf("\t");
                     printf("\n");
 
                 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) {
@@ -152,6 +185,8 @@
 	printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name);
 	printf("OPTIONS:\n");
     printf("\t-d <filename> \t- Debug to file. This is a binary log. Use readlog to print it\n");
+	printf("\t-l\t- Print the date, CC and BCC fields of emails too (by default only the From and Subject)\n");
+	printf("\t-f <date_format> \t- Select the date format in ctime format (by default \"%%F %%T\")\n");
 	printf("\t-h\t- Help. This screen\n");
 	printf("\t-V\t- Version. Display program version\n");
 	DEBUG_RET();
@@ -178,12 +213,22 @@
     char *temp  = NULL; //temporary char pointer
     int  c;
     char *d_log = NULL;
+    struct options o;
+    o.long_format = 0;
+    char *defaultfmtdate = "%F %T";
+    o.date_format = defaultfmtdate;
 
-	while ((c = getopt(argc, argv, "d:hV"))!= -1) {
+	while ((c = getopt(argc, argv, "d:f:lhV"))!= -1) {
 		switch (c) {
 			case 'd':
 				d_log = optarg;
 				break;
+			case 'f':
+				o.date_format = optarg;
+				break;
+			case 'l':
+				o.long_format = 1;
+				break;
 			case 'h':
 				usage(argv[0]);
 				exit(0);
@@ -242,7 +287,7 @@
     d_ptr = pst_getTopOfFolders(&pstfile, item);
     if (!d_ptr) DIE(("Top of folders record not found. Cannot continue\n"));
 
-    process(item, d_ptr->child);    // do the childred of TOPF
+    process(item, d_ptr->child, o);    // do the childred of TOPF
     pst_freeItem(item);
     pst_close(&pstfile);
 
--- a/src/timeconv.c	Mon Nov 20 08:19:28 2017 -0800
+++ b/src/timeconv.c	Thu Dec 07 08:43:57 2017 -0800
@@ -8,6 +8,11 @@
     return ctime_r(&t, result);
 }
 
+size_t pst_fileTimeToString(const FILETIME* filetime, const char* date_format, char* result) {
+    time_t t;
+    t = pst_fileTimeToUnixTime(filetime);
+    return strftime(result, MAXDATEFMTLEN-1, date_format, localtime(&t));
+}
 
 void pst_fileTimeToStructTM (const FILETIME *filetime, struct tm *result) {
     time_t t1;
--- a/src/timeconv.h	Mon Nov 20 08:19:28 2017 -0800
+++ b/src/timeconv.h	Thu Dec 07 08:43:57 2017 -0800
@@ -24,6 +24,14 @@
        @return     result time_t value
      */
     time_t pst_fileTimeToUnixTime( const FILETIME* filetime);
+
+    /** Convert a FILETIME to string in date_format format.
+       @param[in]  filetime time structure to be converted
+       @param[in]  string ctime_r format of output date
+       @param[out] result   pointer to output buffer, must be at least 30 bytes.
+       @return     result size_t value returned by strftime
+     */
+    size_t pst_fileTimeToString( const FILETIME* filetime, const char* date_format, char* result);
 #ifdef __cplusplus
 }
 #endif
--- a/xml/libpst.in	Mon Nov 20 08:19:28 2017 -0800
+++ b/xml/libpst.in	Thu Dec 07 08:43:57 2017 -0800
@@ -35,7 +35,7 @@
 
     <refentry id="readpst.1">
         <refentryinfo>
-            <date>2016-08-29</date>
+            <date>2017-12-07</date>
         </refentryinfo>
 
         <refmeta>
@@ -325,6 +325,8 @@
                 <command>lspst</command>
                 <arg><option>-V</option></arg>
                 <arg><option>-d <replaceable class="parameter">debug-file</replaceable></option></arg>
+                <arg><option>-f <replaceable class="parameter">date-format</replaceable></option></arg>
+                <arg><option>-l</option></arg>
                 <arg><option>-h</option></arg>
                 <arg choice='plain'>pstfile</arg>
             </cmdsynopsis>
@@ -347,6 +349,18 @@
                     </para></listitem>
                 </varlistentry>
                 <varlistentry>
+                    <term>-f <replaceable class="parameter">date-format</replaceable></term>
+                    <listitem><para>
+                        Select the date format for long format listing. Defaults to "%F %T".
+                    </para></listitem>
+                </varlistentry>
+                <varlistentry>
+                    <term>-l</term>
+                    <listitem><para>
+                        Use long format listing to show the Date, CC and BCC headers.
+                    </para></listitem>
+                </varlistentry>
+                <varlistentry>
                     <term>-h</term>
                     <listitem><para>
                         Show summary of options and exit.
@@ -400,7 +414,7 @@
 
     <refentry id="pst2ldif.1">
         <refentryinfo>
-            <date>2016-08-29</date>
+            <date>2017-12-07</date>
         </refentryinfo>
 
         <refmeta>
@@ -568,7 +582,7 @@
 
     <refentry id="pst2dii.1">
         <refentryinfo>
-            <date>2016-08-29</date>
+            <date>2017-12-07</date>
         </refentryinfo>
 
         <refmeta>
@@ -701,7 +715,7 @@
 
     <refentry id="pst.5">
         <refentryinfo>
-            <date>2016-08-29</date>
+            <date>2017-12-07</date>
         </refentryinfo>
 
         <refmeta>