Repository navigation
Expand file tree
/
Copy pathexample_draft_save_message.py
More file actions
129 lines (103 loc) · 3.26 KB
/
Copy pathexample_draft_save_message.py
File metadata and controls
129 lines (103 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import base64
import random
import string
import configparser
import os
import bex_api
from cryptography.hazmat.primitives import serialization
from cryptography.hazmat.primitives import hashes
import cryptography.hazmat.primitives.serialization.pkcs12
"""
***************************************************
GET THE CONFIG FROM FILE OR DEFINE CONFIG ARRAY
***************************************************
"""
__current_path = os.path.dirname(os.path.abspath(__file__)) #os.getcwd()
__config=[]
__config_file=__current_path+'/private.config.ini'
if os.path.exists(__config_file):
__config = configparser.ConfigParser()
__config.read(__config_file)
else :
__config["SOFTWARETOKEN"]["B64"] = "...."
__config["SOFTWARETOKEN"]["FILE"] = "...."
__config["SOFTWARETOKEN"]["PWD"] = "...."
__DEBUG__ = True
sw_token = __config["SOFTWARETOKEN"]["FILE"]
sw_pin = __config["SOFTWARETOKEN"]["PWD"]
token_b64 = __config["SOFTWARETOKEN"]["B64"]
# Login
token, safeId, sessionKey = bex_api.bex_login(sw_token, sw_pin, token_b64)
if __DEBUG__:
print("token: " + token)
print("safeId: " + safeId)
print("sessionKey: " + base64.b64encode(sessionKey).decode('ascii'))
# sendMessage/saveMessage
postboxSafeId = safeId
msg_infos = {
"betreff": "WIN PY: Test mit Anhang",
"aktz_sender": "debug",
"aktz_rcv": "debug",
"msg_text": "This is a simple test message",
"is_eeb": False,
"dringend": False,
"pruefen": False,
"receivers": ["DE.BRAK_SPT .... INSERT SAFE ID"],
"attachments":
[
"01_myText.txt"
],
"is_eeb_response": False,
"eeb_fremdid": "",
"eeb_date": "",
"verfahrensgegenstand": "",
"eeb_erforderlich": True,
"eeb_accept": False,
"xj": True,
"nachrichten_typ": "ALLGEMEINE_NACHRICHT"
}
msg_att = {
"attachments": [
{
"name" : "01_myText.txt",
"data" : "TXkgdGV4dCAx",
"att_type": ""
}
]
}
info = ''
token, info, messageId = bex_api.bea_save_message(token, postboxSafeId, msg_infos, msg_att, sessionKey)
if __DEBUG__:
print('info saveMessage:')
print(info)
print("messageId: ", messageId)
message_draft, msg_infos, msg_att = bex_api.bea_init_message_draft(token, messageId, sessionKey)
if __DEBUG__:
print('bea_init_message_draft:')
print("message_draft: ", message_draft)
print("msg_infos: ", msg_infos)
print("msg_att: ", msg_att)
#remove xj
msg_infos["attachments"].remove("xjustiz_nachricht.xml")
for a in msg_att["attachments"]:
if(a["name"] == "xjustiz_nachricht.xml"):
msg_att["attachments"].remove(a)
break
# append a new attachment
your_file="xyz YPOUR FILE HERE TO ADD"
your_file_fullpath=os.path.join(__current_path,your_file)
my_att_bin = b''
f = open(your_file_fullpath, "rb")
my_att_bin=f.read()
msg_infos["attachments"].append(your_file)
att_tmp = {
"name" : your_file,
"data" : base64.b64encode(my_att_bin).decode('ascii'),
"att_type": ""
}
msg_att["attachments"].append(att_tmp)
token, info, messageId = bex_api.bea_save_message(token, postboxSafeId, msg_infos, msg_att, sessionKey, message_draft)
if __DEBUG__:
print('info saveMessage:')
print(info)
print("messageId: ", messageId)