67 const double sz = 10.0;
74 #define C_TIME_SIZE 500 83 printf(
"pst2dii v%s\n",
VERSION);
84 #if BYTE_ORDER == BIG_ENDIAN 85 printf(
"Big Endian implementation being used.\n");
86 #elif BYTE_ORDER == LITTLE_ENDIAN 87 printf(
"Little Endian implementation being used.\n");
89 # error "Byte order not supported by this library" 98 printf(
"Usage: %s -f ttf-font-file [OPTIONS] {PST FILENAME}\n",
prog_name);
99 printf(
"\t-f ttf-font-file \t- Set the font file\n");
100 printf(
"OPTIONS:\n");
101 printf(
"\t-B bates-prefix \t- Set the bates prefix string\n");
102 printf(
"\t-O dii-output-file\t- Set the dii load file output filename\n");
103 printf(
"\t-V \t- Version. Display program version\n");
104 printf(
"\t-b bates-number \t- Set the starting bates sequence number\n");
105 printf(
"\t-c bates-color \t- Specify the color of the bates stamps as 6 digit hex\n");
106 printf(
"\t-d filename \t- Debug to file.\n");
107 printf(
"\t-h \t- Help. This screen\n");
108 printf(
"\t-o dirname \t- Output directory to write files to.\n");
135 const char *bad =
"Microsoft Mail Internet Headers";
136 if (strncmp(headers, bad, strlen(bad)) == 0) {
138 char *pc = strchr(headers,
'\n');
147 char *t = strdup(fname.c_str());
155 while ((t = strpbrk(t,
" /\\:"))) {
160 if (fixed) fname = string(tt);
179 const char* f_name = fname.c_str();
182 if (!attach_filename) {
188 temp = (
char*)
pst_malloc(len+strlen(attach_filename));
195 }
while ((fp = fopen(temp,
"r")) && ++x < 99999999);
197 DIE((
"error finding attachment name. exhausted possibilities to %s\n", temp));
200 DEBUG_INFO((
"Saving attachment to %s\n", temp));
201 if (!(fp = fopen(temp,
"wb"))) {
202 DEBUG_WARN((
"write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp));
208 if (temp) free(temp);
222 gdFTStringExtra strex;
223 strex.flags = gdFTEX_RESOLUTION;
224 strex.linespacing = 1.20;
229 memcpy(xline, line, len);
233 while ((p = strchr(l,
'&'))) {
236 if (err) printf(
"%s", err);
240 if (err) printf(
"%s", err);
244 if (err) printf(
"%s", err);
263 while (*line ==
'\t') {
265 memset(blanks,
' ', 5);
270 int n = strlen(line);
286 while ((p = strchr(line,
'\n'))) {
311 gdImageColorAllocate(
image, 255, 255, 255);
316 red = gdImageColorAllocate(
image, r, g, b);
318 gdFTStringExtra strex;
319 strex.flags = gdFTEX_RESOLUTION;
320 strex.linespacing = 1.20;
327 if (err) printf(
"%s", err);
347 int len = 4 + 11 + 4 +1;
350 FILE *pngout = fopen(fn,
"wb");
352 gdImagePng(
image, pngout);
355 gdImageDestroy(
image);
387 remove((*i).c_str());
394 static void write_simple(
const char *tag,
const char *value);
397 if (value) fprintf(
dii_file,
"@%s %s\n", tag, value);
401 static void write_simple(
const char *tag,
string value);
404 fprintf(
dii_file,
"@%s %s\n", tag, value.c_str());
408 static void write_simple(
const char *tag,
const char *value,
const char *value2);
409 static void write_simple(
const char *tag,
const char *value,
const char *value2)
412 if (value2) fprintf(
dii_file,
"@%s \"%s\" <%s>\n", tag, value, value2);
413 else fprintf(
dii_file,
"@%s \"%s\"\n", tag, value);
422 int len = strlen(field) + 4;
424 snprintf(f, len,
"\n%s: ", field);
425 char *p = strstr(headers, f);
428 char *n = strchr(p,
'\n');
464 snprintf(folder_line,
sizeof(folder_line),
"pst folder = %s\n", f.
name.c_str());
486 strftime(c_time,
C_TIME_SIZE,
"%T+0000", gmtime(&t));
494 strftime(c_time,
C_TIME_SIZE,
"%T+0000", gmtime(&t));
513 int len = strlen(soh);
514 if (!len || (soh[len-1] !=
'\n')) {
515 snprintf(line,
sizeof(line),
"\n");
522 if (!temp) temp =
"";
527 snprintf(line,
sizeof(line),
"Subject: %s\n", item->
subject.
str);
529 snprintf(line,
sizeof(line),
"Subject: \n");
544 strftime(c_time,
C_TIME_SIZE,
"%a, %d %b %Y %H:%M:%S %z", gmtime(&em_time));
545 snprintf(line,
sizeof(line),
"Date: %s\n", c_time);
549 snprintf(line,
sizeof(line),
"\n");
563 snprintf(ln,
sizeof(ln),
"%s",
"The body of this email is encrypted. This isn't supported yet, but the body is now an attachment\n");
573 DEBUG_INFO((
"Attempting Attachment encoding\n"));
574 if (attach->data.data || attach->i_id) {
576 fprintf(
dii_file,
"@EATTACH %s\n", an.c_str());
580 fprintf(
dii_file,
"@BATESBEG %d\n", bates);
609 for (; d_ptr; d_ptr = d_ptr->
next) {
616 fprintf(stderr,
"entering folder %s\n", item->
file_as.
str);
637 int main(
int argc,
char*
const* argv)
646 while ((c =
getopt(argc, argv,
"B:b:c:d:f:o:O:Vh"))!= -1) {
699 if (!d_log) d_log =
"pst2dii.log";
712 DIE((
"Could not get root record\n"));
718 DIE((
"Top of folders record not found. Cannot continue\n"));
pst_string sender_address
mapi element 0x0065 PR_SENT_REPRESENTING_EMAIL_ADDRESS
static void print_pdf_single(const char *line, int color)
static void check_filename(string &fname)
pst_binary encrypted_htmlbody
mapi element 0x6f02
static void print_pdf_short(const char *line, int len, int color)
int32_t flags
mapi element 0x0e07 PR_MESSAGE_FLAGS
pst_string subject
mapi element 0x0037 PR_SUBJECT
static void print_pdf(char *line)
pst_string header
mapi element 0x007d PR_TRANSPORT_MESSAGE_HEADERS
static void write_simple(const char *tag, const char *value)
void pst_freeItem(pst_item *item)
Free the item returned by pst_parse_item().
int pst_load_extended_attributes(pst_file *pf)
Try to load the extended attributes from the pst file.
void * pst_malloc(size_t size)
pst_binary encrypted_body
mapi element 0x6f04
int pst_close(pst_file *pf)
Close a pst file.
#define PST_TYPE_SCHEDULE
pst_string outlook_sender
mapi element 0x003b PR_SENT_REPRESENTING_SEARCH_KEY
static string write_separate_attachment(string fname, pst_item_attach *current_attach, int attach_num, pst_file *pst)
This contains the common mapi elements, and pointers to structures for each major mapi item type...
int getopt(int argc, char *const *argv, char *optstring)
This contains the attachment related mapi elements.
static void write_normal_email(file_ll &f, pst_item *item, pst_file *pst)
static string extract_header(char *headers, const char *field)
pst_string file_as
mapi element 0x3001 PR_DISPLAY_NAME
static void create_enter_dir(file_ll &f, file_ll *parent, pst_item *item)
static void process(pst_item *outeritem, file_ll *parent, pst_desc_tree *d_ptr)
pst_string messageid
mapi element 0x1035
struct pst_desc_tree * next
pst_desc_tree * pst_getTopOfFolders(pst_file *pf, const pst_item *root)
Get the top of folders descriptor tree.
int main(int argc, char *const *argv)
struct pst_desc_tree * child
int pst_open(pst_file *pf, const char *name, const char *charset)
Open a pst file.
static void close_enter_dir(file_ll &f)
time_t pst_fileTimeToUnixTime(const FILETIME *filetime)
Convert a FILETIME to unix time_t value.
pst_string cc_address
mapi element 0x0e03 PR_DISPLAY_CC
pst_string sentto_address
mapi element 0x0e04 PR_DISPLAY_TO
FILETIME * sent_date
mapi element 0x0039 PR_CLIENT_SUBMIT_TIME
pst_string filename1
mapi element 0x3704 PR_ATTACH_FILENAME
pst_string body
mapi element 0x1000 PR_BODY
pst_item_message_store * message_store
message store mapi elements
static void open_pdf(char *line)
FILETIME * arrival_date
mapi element 0x0e06 PR_MESSAGE_DELIVERY_TIME
#define RET_DERROR(res, ret_val, x)
static char * removeCR(char *c)
pst_string bcc_address
mapi element 0x0e02 PR_DISPLAY_BCC
static char * skip_header_prologue(char *headers)
pst_string htmlbody
mapi element 0x1013
int type
derived from mapi elements 0x001a PR_MESSAGE_CLASS or 0x3613 PR_CONTAINER_CLASS
pst_string outlook_sender_name
mapi element 0x0042 PR_SENT_REPRESENTING_NAME
static void print_pdf_only(char *line, int color)
pst_item * pst_parse_item(pst_file *pf, pst_desc_tree *d_ptr, pst_id2_tree *m_head)
Process a high level object from the pst file.
pst_string filename2
mapi element 0x3707 PR_ATTACH_LONG_FILENAME
size_t pst_attach_to_file(pst_file *pf, pst_item_attach *attach, FILE *fp)
Write a binary attachment to a file.
vector< string > png_names
pst_desc_tree * d_head
the head and tail of the top level of the descriptor tree
pst_string recip_address
mapi element 0x0076 PR_RECEIVED_BY_EMAIL_ADDRESS
pst_item_email * email
email mapi elements
const char * bates_prefix
pst_item_attach * attach
linked list of attachments
#define DEBUG_INIT(fname, mutex)
struct pst_item_attach * next
int pst_load_index(pst_file *pf)
Load the index entries from the pst file.
const char * output_directory
size_t pst_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
fwrite with checking for null pointer.
pst_item_folder * folder
folder mapi elements
void pst_convert_utf8_null(pst_item *item, pst_string *str)
Convert str to utf8 if possible; null strings are preserved.
int32_t item_count
mapi element 0x3602 PR_CONTENT_COUNT
void pst_convert_utf8(pst_item *item, pst_string *str)
Convert str to utf8 if possible; null strings are converted into empty strings.