libyal / libpff

Library and tools to access the Personal Folder File (PFF) and the Offline Folder File (OFF) format
GNU Lesser General Public License v3.0
286 stars 74 forks source link

Creating or modifying a PST file? #116

Closed kartikeysemwal closed 1 year ago

kartikeysemwal commented 1 year ago

Hi, thanks for creating the library. My requirement is to create or modify PST. Is your library able to do this task? Also, I successfully built the libpff repo and started writing some basic C++ code to get used to the functions. When using the function libpff_item_get_utf8_display_name_size, I am getting error Error C4996 'libpff_item_get_entry_value_utf8_string_size': was declared deprecated. Can you please provide some helpful suggestions and recommended practices to get started with this library.

`

include

include

include

include

int main() { std::cout << "Hello World!\n";

libpff_error_t* error = NULL;
libpff_file_t* file = NULL;

if (libpff_file_initialize(&file, &error) != 1)
{
    fprintf(stderr, "Unable to initialize file.\n");

    libpff_error_free(&error);

    exit(EXIT_FAILURE);
}

std::string filename = "D:\\ksemwal\\Temp\\PSTFiles\\SimpleEmailPST.pst";

if (libpff_file_open(file, filename.c_str(), LIBPFF_OPEN_READ, &error) != 1)
{
    fprintf(stderr, "Unable to open file.\n");

    libpff_file_free(&file, NULL);
    libpff_error_free(&error);

    exit(EXIT_FAILURE);
}

libpff_item_t* messageStore = NULL;

if (libpff_file_get_message_store(file, &messageStore, &error) != 1)
{
    fprintf(stderr, "Unable to open message store.\n");
    libpff_file_free(&file, NULL);
    libpff_error_free(&error);

    exit(EXIT_FAILURE);
}

int numberOfSubItems = 0;
if (libpff_item_get_number_of_sub_items(messageStore, &numberOfSubItems, &error) != 1)
{
    fprintf(stderr, "Unable to get number of items.\n");
    libpff_file_free(&file, NULL);
    libpff_error_free(&error);

    exit(EXIT_FAILURE);
}

size_t stringSize = 0;
if (libpff_item_get_utf8_display_name_size(messageStore, &stringSize, &error) != 1)
{
    fprintf(stderr, "Unable to open message store.\n");
    libpff_file_free(&file, NULL);
    libpff_error_free(&error);

    exit(EXIT_FAILURE);
}

uint8_t* displayName = NULL;
if (libpff_item_get_utf8_display_name(messageStore, displayName, stringSize, &error) != 1)
{
    fprintf(stderr, "Unable to read display name.\n");
    libpff_file_free(&file, NULL);
    libpff_error_free(&error);

    exit(EXIT_FAILURE);
}

libpff_item_t* root_folder = NULL;
if (libpff_file_get_root_folder(file, &root_folder, &error) != 1)
{
    fprintf(stderr, "Unable to open root folder.\n");
    libpff_file_free(&file, NULL);
    libpff_error_free(&error);

    exit(EXIT_FAILURE);
}

stringSize = 0;
if (libpff_item_get_utf16_display_name_size(root_folder, &stringSize, &error) != 1)
{
    fprintf(stderr, "Unable to read display name..\n");
    libpff_file_free(&file, NULL);
    libpff_error_free(&error);

    exit(EXIT_FAILURE);
}

if (libpff_item_get_number_of_sub_items(root_folder, &numberOfSubItems, &error) != 1)
{
    fprintf(stderr, "Unable to get number of items.\n");
    libpff_file_free(&file, NULL);
    libpff_error_free(&error);

    exit(EXIT_FAILURE);
}

} `

joachimmetz commented 1 year ago

My requirement is to create or modify PST. Is your library able to do this task?

no this project focuses on reading only

Can you please provide some helpful suggestions and recommended practices to get started with this library.

The interface is not that complex. Looks like you figured out most of it already. Also see https://github.com/libyal/libpff/wiki/C-development and the pfftools as example code.

Regarding the depredation warning have a look at https://github.com/libyal/libpff/blob/main/include/libpff.h.in#L1075

kartikeysemwal commented 1 year ago

Thanks for the quick follow up. I will take a look. Thanks