Truxton communication get id

From truxwiki.com
Revision as of 05:46, 1 November 2022 by Sam (talk | contribs) (Created page with "This will retrieve the identifier of the message. It corresponds to the <code>[ID]</code> column of the <code>[Message]</code> table. =Syntax= <source lang="C"> int truxton_c...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This will retrieve the identifier of the message. It corresponds to the [ID] column of the [Message] table.

Syntax

int truxton_communication_get_id( uint64_t communication_handle, char * buffer, size_t buffer_size );

Parameters

communication_handle

The handle returned by calling truxton_communication_create.

buffer

The buffer to write the identifier to.

buffer_size

The number of bytes that can be written to buffer.

Return value

A non-zero value on success, zero on failure.

Sample

 1 #define TAG_ORIGIN_AUTOMATIC (1)
 2 #define TAG_ORIGIN_HUMAN     (2)
 3 
 4 void add_message( uint64_t truxton, uint64_t parent_file )
 5 {
 6    char id[40];
 7    char sender_id[80];
 8 
 9    uint64_t communication = truxton_communication_create( parent_file );
10 
11    uint64_t message_time = truxton_parse_time( "2021-07-29 21:52:53 UTC" );
12 
13    truxton_communication_set_received( communication, message_time );
14    truxton_communication_set_sent( communication, message_time );
15    truxton_communication_set_type( communication, MESSAGE_TYPE_MIME );
16    truxton_communication_set_subject( communication, "Test Message" );
17 
18    if ( truxton_communication_save( communication ) == 0 )
19    {
20       printf( "Failed to add communication to Truxton\n" );
21       truxton_communication_destroy( communication );
22       return;
23    }
24 
25    truxton_communication_get_id( parent_file, id, sizeof(id) );
26    printf( "Saved as id %s\n", id );
27 
28    // Now that we have an id, we can add participants.
29 
30    if ( truxton_communication_add_participant( communication, MESSAGE_PARTICIPANT_FROM, "sam@abc.xyz", sender_id, sizeof(sender_id) ) == 0 )
31    {
32       printf( "Could not save FROM participant.\n" );
33    }
34    else
35    {
36       printf( "Sender id is %s\n", sender_id );
37    }
38 
39    if ( truxton_communication_add_participant( communication, MESSAGE_PARTICIPANT_TO, "laura@abc.xyz", NULL, 0 ) == 0 )
40    {
41       printf( "Could not save TO participant.\n" );
42    }
43 
44    uint64_t message_body_1 = create_message_body_1( truxton );
45    uint64_t message_body_2 = create_message_body_2( truxton );
46    uint64_t attachment_1 = create_attachment_1( truxton );
47    uint64_t attachment_2 = create_attachment_2( truxton );
48 
49    if ( truxton_communication_add_piece( communication, message_body_1, ORIGIN_EMAIL_BODY, 1 ) == 0 )
50    {
51       printf( "Could not add first body to message.\n" );
52    }
53 
54    if ( truxton_communication_add_piece( communication, message_body_1, ORIGIN_EMAIL_BODY, 2 ) == 0 )
55    {
56       printf( "Could not add second body to message.\n" );
57    }
58 
59    if ( truxton_communication_add_piece( communication, attachment_1, ORIGIN_EMAIL_ATTACHMENT, 1 ) == 0 )
60    {
61       printf( "Could not add first attachment to message.\n" );
62    }
63 
64    if ( truxton_communication_add_piece( communication, attachment_2, ORIGIN_EMAIL_ATTACHMENT, 2 ) == 0 )
65    {
66       printf( "Could not add second attachment to message.\n" );
67    }
68 
69    if ( truxton_communication_finished( communication ) == 0 )
70    {
71       printf( "Could not complete message record.\n" );
72    }
73 
74    if ( truxton_communication_tag( communication, "Man Made", "Testing the API", TAG_ORIGIN_HUMAN ) == 0 )
75    {
76       printf( "Could not tag message.\n" );
77    }
78 
79    truxton_communication_destroy( communication );
80 }