Difference between revisions of "Truxton communication add piece"

From truxwiki.com
Jump to navigation Jump to search
Line 25: Line 25:
  
 
=Sample=
 
=Sample=
<source lang="C" highlight="56,61,66,71">
+
<source lang="C" highlight="49,54,59,64" line>
 
#define TAG_ORIGIN_AUTOMATIC (1)
 
#define TAG_ORIGIN_AUTOMATIC (1)
 
#define TAG_ORIGIN_HUMAN    (2)
 
#define TAG_ORIGIN_HUMAN    (2)
Line 36: Line 36:
 
   uint64_t communication = truxton_communication_create( parent_file );
 
   uint64_t communication = truxton_communication_create( parent_file );
  
   FILETIME now;
+
   uint64_t message_time = truxton_parse_time( "2021-07-29 21:52:53 UTC" );
  
  GetSystemTimePreciseAsFileTime( &now );
+
   truxton_communication_set_received( communication, message_time );
 
+
   truxton_communication_set_sent( communication, message_time );
  ULARGE_INTEGER ticks;
 
 
 
  ticks.LowPart = now.dwLowDateTime;
 
  ticks.HighPart = now.dwHighDateTime;
 
 
 
   truxton_communication_set_received( communication, ticks.QuadPart );
 
   truxton_communication_set_sent( communication, ticks.QuadPart );
 
 
   truxton_communication_set_type( communication, MESSAGE_TYPE_MIME );
 
   truxton_communication_set_type( communication, MESSAGE_TYPE_MIME );
 
   truxton_communication_set_subject( communication, "Test Message" );
 
   truxton_communication_set_subject( communication, "Test Message" );

Revision as of 05:40, 1 November 2022

This adds a piece to the message.

Syntax

int truxton_communication_add_piece( uint64_t communication_handle, uint64_t file_handle, uint64_t origin, uint64_t instance );

Parameters

communication_handle

The handle returned by calling truxton_communication_create.

file_handle

The file in Truxton that contains the contents of this piece.

origin

If the file is a message body, it should be ORIGIN_EMAIL_BODY or ORIGIN_CHAT_MESSAGE. If the file is an attachment, it should be ORIGIN_EMAIL_ATTACHMENT or ORIGIN_MMS_ATTACHMENT.

instance

This tells Truxton the number of the body or attachment. Is this the first or second or third attachment?

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 }