Skip to content

Commit

Permalink
Support looking for a MessageStore.db if there are no .imm files in e…
Browse files Browse the repository at this point in the history
…xport-entire-directory mode.
  • Loading branch information
smowton committed Feb 20, 2016
1 parent a921784 commit 12625d7
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 25 deletions.
10 changes: 5 additions & 5 deletions Source/increadimail_convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ extern "C" {

extern HWND global_hwnd;

void email_count(char *, int *, int *);
void email_count(const char *, int *, int *);
//***************************************************************************
// INPUTS:
//
Expand Down Expand Up @@ -73,7 +73,7 @@ extern "C" {
//
//***************************************************************************

void extract_eml_files(char *filename_data, char *, int offset, unsigned int size);
void extract_eml_files(const char *filename_data, char *, int offset, unsigned int size);
//***************************************************************************
// INPUTS:
//
Expand Down Expand Up @@ -145,7 +145,7 @@ extern "C" {
//
//***************************************************************************

void Incredimail_2_Email_Count(char *filename, int *email_total, int *deleted_emails);
void Incredimail_2_Email_Count(const char *filename, int *email_total, int *deleted_emails);
//***************************************************************************
// INPUTS:
//
Expand All @@ -157,9 +157,9 @@ extern "C" {
//
//***************************************************************************

void Incredimail_2_Maildir_Email_Count(char *filename, int *email_total, int *deleted_emails);
void Incredimail_2_Maildir_Email_Count(const char *filename, int *email_total, int *deleted_emails);

void Incredimail_2_Get_Email_Offset_and_Size(char *filename, unsigned int *file_offset, unsigned int *size, int email_index, int *deleted_email);
void Incredimail_2_Get_Email_Offset_and_Size(const char *filename, unsigned int *file_offset, unsigned int *size, int email_index, int *deleted_email);
//***************************************************************************
// INPUTS:
//
Expand Down
14 changes: 6 additions & 8 deletions Source/incredimail_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

const char *ATTACHMENT = "----------[%ImFilePath%]----------";

void email_count( char *filename, int *email_total, int *deleted_emails ) {
void email_count( const char *filename, int *email_total, int *deleted_emails ) {
int dummy = 1;
int i;
int e_count = 0;
Expand Down Expand Up @@ -140,7 +140,7 @@ unsigned int file_size, sizer;
}


void extract_eml_files( char *filename_data, char *eml_filename, int offset, unsigned int size ) {
void extract_eml_files( const char *filename_data, char *eml_filename, int offset, unsigned int size ) {
HANDLE helping_hand;
HANDLE writing_hand;
int j, k, dummy;
Expand Down Expand Up @@ -325,10 +325,8 @@ int total_count = 1;
list_output = CreateFile(temp_filename, GENERIC_WRITE, 0x0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL );

hFind = FindFirstFile(database_filename, &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) {
MessageBox(global_hwnd, "No .imm files found within given directory", "Error!", MB_OK);
if (hFind == INVALID_HANDLE_VALUE)
return -1;
}

sprintf(temp_string, "%s\\%s%c%c", directory_search, FindFileData.cFileName, 0x0D, 0x0A );
WriteFile( list_output, temp_string, (DWORD) strlen( temp_string ), &dummy, NULL );
Expand Down Expand Up @@ -416,7 +414,7 @@ enum INCREDIMAIL_VERSIONS FindIncredimailVersion(char *directory_search) {
return ret;
}

void Incredimail_2_Maildir_Email_Count(char *filename, int *email_total, int *deleted_emails) {
void Incredimail_2_Maildir_Email_Count(const char *filename, int *email_total, int *deleted_emails) {

sqlite3 *db;
sqlite3_stmt *stmt;
Expand Down Expand Up @@ -464,7 +462,7 @@ void Incredimail_2_Maildir_Email_Count(char *filename, int *email_total, int *de

}

void Incredimail_2_Email_Count( char *filename, int *email_total, int *deleted_emails ) {
void Incredimail_2_Email_Count( const char *filename, int *email_total, int *deleted_emails ) {
char sql[MAX_CHAR];
char trimmed_filename[MAX_CHAR];
char containerID[MAX_CHAR];
Expand Down Expand Up @@ -555,7 +553,7 @@ sqlite3_stmt *stmt;
}


void Incredimail_2_Get_Email_Offset_and_Size( char *filename, unsigned int *file_offset, unsigned int *size, int email_index, int *deleted_email ) {
void Incredimail_2_Get_Email_Offset_and_Size( const char *filename, unsigned int *file_offset, unsigned int *size, int email_index, int *deleted_email ) {

sqlite3 *db;
sqlite3_stmt *stmt;
Expand Down
41 changes: 29 additions & 12 deletions Source/winmain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,11 +412,23 @@ struct im2_maildir_folder {

};

void WINAPI process_emails2(const char* im_database_filename, const char* im_attachments_directory);

void WINAPI process_emails() {

char im_database_filename[MAX_CHAR];
char im_attachments_directory[MAX_CHAR];

GetDlgItemText(global_hwnd, IDC_EDIT1, (LPSTR)&im_database_filename, 256); // get the incredimail database name
GetDlgItemText(global_hwnd, IDC_EDIT2, (LPSTR)&im_attachments_directory, 256); // get the attachement directory name

process_emails2(im_database_filename, im_attachments_directory);

}

void WINAPI process_emails2(const char* im_database_filename, const char* im_attachments_directory) {

char im_header_filename[MAX_CHAR];
char im_database_filename[MAX_CHAR];
char im_attachments_directory[MAX_CHAR];
char debug_str[MAX_CHAR];
char new_eml_filename[MAX_CHAR];
char export_directory[MAX_CHAR];
Expand All @@ -430,24 +442,19 @@ int i, result_header, result_database, result_attachment, result_create_temp;
struct _stat buf;
float percent_complete;
int real_count = 0;
char *pdest;
const char *pdest;

enum INCREDIMAIL_VERSIONS incredimail_version;

// Zero out the string names
ZeroMemory( &im_header_filename, sizeof( im_header_filename ) );
ZeroMemory( &im_database_filename, sizeof( im_database_filename ) );
ZeroMemory( &im_attachments_directory, sizeof( im_attachments_directory ) );
ZeroMemory( &new_eml_filename, sizeof( new_eml_filename ) );
ZeroMemory( &export_directory, sizeof( export_directory ) );
ZeroMemory( &temp_path, sizeof( temp_path ) );
ZeroMemory( &temp_filename, sizeof( temp_filename ) );

SendDlgItemMessage( global_hwnd, IDC_PROGRESS1, PBM_SETPOS, 0, 0 ); // reset the progress bar to 0%

GetDlgItemText( global_hwnd, IDC_EDIT1, (LPSTR) &im_database_filename, 256 ); // get the incredimail database name
GetDlgItemText( global_hwnd, IDC_EDIT2, (LPSTR) &im_attachments_directory, 256 ); // get the attachement directory name

pdest = strrchr( im_database_filename, '\\' );
strncpy_s( temp_path, MAX_CHAR, im_database_filename, strlen( im_database_filename ) - strlen( pdest ) );

Expand Down Expand Up @@ -477,8 +484,8 @@ enum INCREDIMAIL_VERSIONS incredimail_version;
}
} else {
// the export directory is based off of the database name
char* extsep = strrchr(im_database_filename, '.');
char* dirsep = strrchr(im_database_filename, '\\');
const char* extsep = strrchr(im_database_filename, '.');
const char* dirsep = strrchr(im_database_filename, '\\');
if (extsep != NULL && (dirsep == NULL || dirsep < extsep))
strncpy_s(export_directory, MAX_CHAR, im_database_filename, (extsep - im_database_filename));
else {
Expand Down Expand Up @@ -718,10 +725,20 @@ enum INCREDIMAIL_VERSIONS incredimail_version;
}
} else {

// This looks for *.imm, for the IncrediMail XE or non-maildir case.
total_count = FindDatabaseFiles( im_database_filename, temp_file_listing );
if (total_count < 0)
if (total_count < 0) {
// See if we can find an IncrediMail 2 Maildir store instead:
std::string storename = std::string(im_database_filename) + "\\MessageStore.db";
struct _stat buf;
if (!_stat(storename.c_str(), &buf))
process_emails2(storename.c_str(), im_attachments_directory);
else {
MessageBox(global_hwnd, "No .imm files and no MessageStore.db found within given directory", "Error!", MB_OK);
}
return;

}

// set the progress bar 2
SendDlgItemMessage( global_hwnd, IDC_PROGRESS2, PBM_SETRANGE, 0, (LPARAM) MAKELPARAM (0, total_count));
SendDlgItemMessage( global_hwnd, IDC_PROGRESS2, PBM_SETSTEP, 1, 0 );
Expand Down

0 comments on commit 12625d7

Please sign in to comment.