libpst

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 diff
     1.1 --- a/AUTHORS	Mon Nov 20 08:19:28 2017 -0800
     1.2 +++ b/AUTHORS	Thu Dec 07 08:43:57 2017 -0800
     1.3 @@ -43,6 +43,7 @@
     1.4      Igor Stroh <igor.stroh@rulim.de>
     1.5      Zachary Travis <ztravis@everlaw.com>
     1.6      Vitaliy Didik <ariman@inbox.ru>
     1.7 +    Alfredo Esteban <aedelatorre@gmail.com>
     1.8  
     1.9  Testing team:
    1.10      Mac OSX - Michael Watson <mike@mikeandgayle.com>
     2.1 --- a/ChangeLog	Mon Nov 20 08:19:28 2017 -0800
     2.2 +++ b/ChangeLog	Thu Dec 07 08:43:57 2017 -0800
     2.3 @@ -1,3 +1,7 @@
     2.4 +LibPST 0.6.72 (2017-12-07)
     2.5 +===============================
     2.6 +    * Alfredo Esteban - add -l and -f options to lspst.
     2.7 +
     2.8  LibPST 0.6.71 (2017-07-21)
     2.9  ===============================
    2.10      * Zachary Travis - Add support for the OST 2013 format, and
     3.1 --- a/configure.in	Mon Nov 20 08:19:28 2017 -0800
     3.2 +++ b/configure.in	Thu Dec 07 08:43:57 2017 -0800
     3.3 @@ -1,5 +1,5 @@
     3.4  AC_PREREQ(2.60)
     3.5 -AC_INIT(libpst,0.6.71,carl@five-ten-sg.com)
     3.6 +AC_INIT(libpst,0.6.72,carl@five-ten-sg.com)
     3.7  AC_CONFIG_SRCDIR([src/libpst.c])
     3.8  AC_CONFIG_HEADER([config.h])
     3.9  AC_CONFIG_MACRO_DIR([m4])
     4.1 --- a/src/define.h	Mon Nov 20 08:19:28 2017 -0800
     4.2 +++ b/src/define.h	Thu Dec 07 08:43:57 2017 -0800
     4.3 @@ -256,5 +256,6 @@
     4.4  
     4.5  #define PST_LE_GET_INT8(p) (*(int8_t const *)(p))
     4.6  
     4.7 +#define MAXDATEFMTLEN 40
     4.8  
     4.9  #endif //DEFINEH_H
     5.1 --- a/src/lspst.c	Mon Nov 20 08:19:28 2017 -0800
     5.2 +++ b/src/lspst.c	Thu Dec 07 08:43:57 2017 -0800
     5.3 @@ -16,6 +16,10 @@
     5.4      int32_t type;
     5.5  };
     5.6  
     5.7 +struct options {
     5.8 +    int long_format;
     5.9 +    char *date_format;
    5.10 +};
    5.11  
    5.12  void canonicalize_filename(char *fname);
    5.13  void debug_print(char *fmt, ...);
    5.14 @@ -42,13 +46,13 @@
    5.15      free(f->dname);
    5.16  }
    5.17  
    5.18 -
    5.19 -void process(pst_item *outeritem, pst_desc_tree *d_ptr)
    5.20 +void process(pst_item *outeritem, pst_desc_tree *d_ptr, struct options o)
    5.21  {
    5.22      struct file_ll ff;
    5.23      pst_item *item = NULL;
    5.24      char *result = NULL;
    5.25      size_t resultlen = 0;
    5.26 +    size_t dateresultlen;
    5.27  
    5.28      DEBUG_ENT("process");
    5.29      memset(&ff, 0, sizeof(ff));
    5.30 @@ -74,7 +78,7 @@
    5.31                      // if this is a folder, we want to recurse into it
    5.32                      pst_convert_utf8(item, &item->file_as);
    5.33                      printf("Folder \"%s\"\n", item->file_as.str);
    5.34 -                    process(item, d_ptr->child);
    5.35 +                    process(item, d_ptr->child, o);
    5.36  
    5.37                  } else if (item->contact && (item->type == PST_TYPE_CONTACT)) {
    5.38                      if (!ff.type) ff.type = item->type;
    5.39 @@ -94,10 +98,39 @@
    5.40                          DEBUG_INFO(("I have an email, but the folder isn't an email folder. Processing anyway\n"));
    5.41                      }
    5.42                      printf("Email");
    5.43 +                    if (o.long_format == 1) {
    5.44 +                        if (item->email->arrival_date) {
    5.45 +                            char time_buffer[MAXDATEFMTLEN];
    5.46 +                            dateresultlen = pst_fileTimeToString(item->email->arrival_date, o.date_format, time_buffer);
    5.47 +                            if (dateresultlen < 1)
    5.48 +                                DIE(("Date format error in -f option.\n"));
    5.49 +                            printf("\tDate: %s", time_buffer);
    5.50 +                        }
    5.51 +                        else
    5.52 +                            printf("\t");
    5.53 +                    }
    5.54                      if (item->email->outlook_sender_name.str)
    5.55                          printf("\tFrom: %s", item->email->outlook_sender_name.str);
    5.56 +                    else
    5.57 +                        printf("\t");
    5.58 +                    if (o.long_format == 1) {
    5.59 +                        if (item->email->outlook_recipient_name.str)
    5.60 +                            printf("\tTo: %s", item->email->outlook_recipient_name.str);
    5.61 +                        else
    5.62 +                            printf("\t");
    5.63 +                        if (item->email->cc_address.str)
    5.64 +                            printf("\tCC: %s", item->email->cc_address.str);
    5.65 +                        else
    5.66 +                            printf("\t");
    5.67 +                        if (item->email->bcc_address.str)
    5.68 +                            printf("\tBCC: %s", item->email->bcc_address.str);
    5.69 +                        else
    5.70 +                            printf("\t");
    5.71 +                    }
    5.72                      if (item->subject.str)
    5.73                          printf("\tSubject: %s", item->subject.str);
    5.74 +                    else
    5.75 +                        printf("\t");
    5.76                      printf("\n");
    5.77  
    5.78                  } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) {
    5.79 @@ -152,6 +185,8 @@
    5.80  	printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name);
    5.81  	printf("OPTIONS:\n");
    5.82      printf("\t-d <filename> \t- Debug to file. This is a binary log. Use readlog to print it\n");
    5.83 +	printf("\t-l\t- Print the date, CC and BCC fields of emails too (by default only the From and Subject)\n");
    5.84 +	printf("\t-f <date_format> \t- Select the date format in ctime format (by default \"%%F %%T\")\n");
    5.85  	printf("\t-h\t- Help. This screen\n");
    5.86  	printf("\t-V\t- Version. Display program version\n");
    5.87  	DEBUG_RET();
    5.88 @@ -178,12 +213,22 @@
    5.89      char *temp  = NULL; //temporary char pointer
    5.90      int  c;
    5.91      char *d_log = NULL;
    5.92 +    struct options o;
    5.93 +    o.long_format = 0;
    5.94 +    char *defaultfmtdate = "%F %T";
    5.95 +    o.date_format = defaultfmtdate;
    5.96  
    5.97 -	while ((c = getopt(argc, argv, "d:hV"))!= -1) {
    5.98 +	while ((c = getopt(argc, argv, "d:f:lhV"))!= -1) {
    5.99  		switch (c) {
   5.100  			case 'd':
   5.101  				d_log = optarg;
   5.102  				break;
   5.103 +			case 'f':
   5.104 +				o.date_format = optarg;
   5.105 +				break;
   5.106 +			case 'l':
   5.107 +				o.long_format = 1;
   5.108 +				break;
   5.109  			case 'h':
   5.110  				usage(argv[0]);
   5.111  				exit(0);
   5.112 @@ -242,7 +287,7 @@
   5.113      d_ptr = pst_getTopOfFolders(&pstfile, item);
   5.114      if (!d_ptr) DIE(("Top of folders record not found. Cannot continue\n"));
   5.115  
   5.116 -    process(item, d_ptr->child);    // do the childred of TOPF
   5.117 +    process(item, d_ptr->child, o);    // do the childred of TOPF
   5.118      pst_freeItem(item);
   5.119      pst_close(&pstfile);
   5.120  
     6.1 --- a/src/timeconv.c	Mon Nov 20 08:19:28 2017 -0800
     6.2 +++ b/src/timeconv.c	Thu Dec 07 08:43:57 2017 -0800
     6.3 @@ -8,6 +8,11 @@
     6.4      return ctime_r(&t, result);
     6.5  }
     6.6  
     6.7 +size_t pst_fileTimeToString(const FILETIME* filetime, const char* date_format, char* result) {
     6.8 +    time_t t;
     6.9 +    t = pst_fileTimeToUnixTime(filetime);
    6.10 +    return strftime(result, MAXDATEFMTLEN-1, date_format, localtime(&t));
    6.11 +}
    6.12  
    6.13  void pst_fileTimeToStructTM (const FILETIME *filetime, struct tm *result) {
    6.14      time_t t1;
     7.1 --- a/src/timeconv.h	Mon Nov 20 08:19:28 2017 -0800
     7.2 +++ b/src/timeconv.h	Thu Dec 07 08:43:57 2017 -0800
     7.3 @@ -24,6 +24,14 @@
     7.4         @return     result time_t value
     7.5       */
     7.6      time_t pst_fileTimeToUnixTime( const FILETIME* filetime);
     7.7 +
     7.8 +    /** Convert a FILETIME to string in date_format format.
     7.9 +       @param[in]  filetime time structure to be converted
    7.10 +       @param[in]  string ctime_r format of output date
    7.11 +       @param[out] result   pointer to output buffer, must be at least 30 bytes.
    7.12 +       @return     result size_t value returned by strftime
    7.13 +     */
    7.14 +    size_t pst_fileTimeToString( const FILETIME* filetime, const char* date_format, char* result);
    7.15  #ifdef __cplusplus
    7.16  }
    7.17  #endif
     8.1 --- a/xml/libpst.in	Mon Nov 20 08:19:28 2017 -0800
     8.2 +++ b/xml/libpst.in	Thu Dec 07 08:43:57 2017 -0800
     8.3 @@ -35,7 +35,7 @@
     8.4  
     8.5      <refentry id="readpst.1">
     8.6          <refentryinfo>
     8.7 -            <date>2016-08-29</date>
     8.8 +            <date>2017-12-07</date>
     8.9          </refentryinfo>
    8.10  
    8.11          <refmeta>
    8.12 @@ -325,6 +325,8 @@
    8.13                  <command>lspst</command>
    8.14                  <arg><option>-V</option></arg>
    8.15                  <arg><option>-d <replaceable class="parameter">debug-file</replaceable></option></arg>
    8.16 +                <arg><option>-f <replaceable class="parameter">date-format</replaceable></option></arg>
    8.17 +                <arg><option>-l</option></arg>
    8.18                  <arg><option>-h</option></arg>
    8.19                  <arg choice='plain'>pstfile</arg>
    8.20              </cmdsynopsis>
    8.21 @@ -347,6 +349,18 @@
    8.22                      </para></listitem>
    8.23                  </varlistentry>
    8.24                  <varlistentry>
    8.25 +                    <term>-f <replaceable class="parameter">date-format</replaceable></term>
    8.26 +                    <listitem><para>
    8.27 +                        Select the date format for long format listing. Defaults to "%F %T".
    8.28 +                    </para></listitem>
    8.29 +                </varlistentry>
    8.30 +                <varlistentry>
    8.31 +                    <term>-l</term>
    8.32 +                    <listitem><para>
    8.33 +                        Use long format listing to show the Date, CC and BCC headers.
    8.34 +                    </para></listitem>
    8.35 +                </varlistentry>
    8.36 +                <varlistentry>
    8.37                      <term>-h</term>
    8.38                      <listitem><para>
    8.39                          Show summary of options and exit.
    8.40 @@ -400,7 +414,7 @@
    8.41  
    8.42      <refentry id="pst2ldif.1">
    8.43          <refentryinfo>
    8.44 -            <date>2016-08-29</date>
    8.45 +            <date>2017-12-07</date>
    8.46          </refentryinfo>
    8.47  
    8.48          <refmeta>
    8.49 @@ -568,7 +582,7 @@
    8.50  
    8.51      <refentry id="pst2dii.1">
    8.52          <refentryinfo>
    8.53 -            <date>2016-08-29</date>
    8.54 +            <date>2017-12-07</date>
    8.55          </refentryinfo>
    8.56  
    8.57          <refmeta>
    8.58 @@ -701,7 +715,7 @@
    8.59  
    8.60      <refentry id="pst.5">
    8.61          <refentryinfo>
    8.62 -            <date>2016-08-29</date>
    8.63 +            <date>2017-12-07</date>
    8.64          </refentryinfo>
    8.65  
    8.66          <refmeta>