Compare commits
2205 Commits
fix_upload
...
sqlx
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
df546b9d2e | ||
|
|
5c13d2322a | ||
|
|
2d5caf9d3e | ||
|
|
876e3ed58e | ||
|
|
cdb5f0d536 | ||
|
|
0d791bb6b3 | ||
|
|
9152f93a46 | ||
|
|
6a4b6fddac | ||
|
|
e3c90aff22 | ||
|
|
b7464f7a5c | ||
|
|
53128cc64b | ||
|
|
ccf8eeacd6 | ||
|
|
aeb8a2e260 | ||
|
|
93797bc82f | ||
|
|
07236efc45 | ||
|
|
0fbddc939b | ||
|
|
a031151587 | ||
|
|
545ff4f7ba | ||
|
|
73e695537a | ||
|
|
16e3c113b7 | ||
|
|
88d7bf49ff | ||
|
|
74ea884aa4 | ||
|
|
16c53637d9 | ||
|
|
f63f0550b0 | ||
|
|
530503932b | ||
|
|
d2dc4edd82 | ||
|
|
8de1bc6cbd | ||
|
|
76e39bfa7c | ||
|
|
cf09942737 | ||
|
|
6fe1f01c5f | ||
|
|
f880d6188b | ||
|
|
22c62ea6af | ||
|
|
e3af3a24a8 | ||
|
|
7bfadb14ea | ||
|
|
75d20b899a | ||
|
|
31a5811241 | ||
|
|
cd1f5bf229 | ||
|
|
632fc19f41 | ||
|
|
7ad95ea165 | ||
|
|
9d7b756ddb | ||
|
|
73412db267 | ||
|
|
059a7bcd7f | ||
|
|
3e47564b2f | ||
|
|
d8be0cdf35 | ||
|
|
26a44b6d32 | ||
|
|
12eacaae36 | ||
|
|
2d8148a1a3 | ||
|
|
916007ed2d | ||
|
|
b91b88e11b | ||
|
|
b6c0f44608 | ||
|
|
2a623541d7 | ||
|
|
0007e93e80 | ||
|
|
c655fd8a64 | ||
|
|
ad531876fd | ||
|
|
53bee68acb | ||
|
|
b5400cf551 | ||
|
|
491af1b583 | ||
|
|
5b1d06cb28 | ||
|
|
7df5195d77 | ||
|
|
baff13ecab | ||
|
|
a7bf05bebb | ||
|
|
aa9b5da1c0 | ||
|
|
dfd705f9c6 | ||
|
|
472c0bcea5 | ||
|
|
8c2af132c8 | ||
|
|
79145576ab | ||
|
|
8ca55b0f60 | ||
|
|
74cb4ca1cd | ||
|
|
351e5dc6f3 | ||
|
|
4eee4a08e7 | ||
|
|
b5fa0f8924 | ||
|
|
baba91c054 | ||
|
|
40c9c2752b | ||
|
|
f4a1a526f5 | ||
|
|
7d80179ed1 | ||
|
|
71080ed6d5 | ||
|
|
44037dd711 | ||
|
|
bc275d8670 | ||
|
|
eb29f9c4c1 | ||
|
|
6340b278d9 | ||
|
|
519e1c1cd0 | ||
|
|
d2320394ca | ||
|
|
9307f2d49f | ||
|
|
7362941245 | ||
|
|
f7c7f414ed | ||
|
|
23d6012c1f | ||
|
|
15b30ceed1 | ||
|
|
45b871f76d | ||
|
|
9f1112833f | ||
|
|
fc88bff32f | ||
|
|
bbf049e95b | ||
|
|
52dfa9b536 | ||
|
|
1fe85dfb3c | ||
|
|
27ff1c4a75 | ||
|
|
adf4035775 | ||
|
|
990c80cedf | ||
|
|
8ebce0c861 | ||
|
|
ffb6a84b1f | ||
|
|
c60ec00aac | ||
|
|
dd3f81a556 | ||
|
|
8938cb2573 | ||
|
|
995660020b | ||
|
|
7997e7dde4 | ||
|
|
20ad98d168 | ||
|
|
c827c9d209 | ||
|
|
bde97b20e9 | ||
|
|
777df24c75 | ||
|
|
e1711855cc | ||
|
|
3899d70b3c | ||
|
|
e7aee5b4f4 | ||
|
|
bd2a7a3d40 | ||
|
|
2e59d5674e | ||
|
|
98b5f768b6 | ||
|
|
b7d0f29002 | ||
|
|
df9cb5e3b8 | ||
|
|
a30486112f | ||
|
|
016b96e30e | ||
|
|
6b763bf417 | ||
|
|
6ded0d3bc1 | ||
|
|
f0837cfa73 | ||
|
|
8350729cbb | ||
|
|
3757e5dca1 | ||
|
|
f02c17cae4 | ||
|
|
e08e817988 | ||
|
|
dad6381519 | ||
|
|
d35cf7d6a2 | ||
|
|
1d34e1f27a | ||
|
|
e03246d105 | ||
|
|
944f1ec005 | ||
|
|
d208905473 | ||
|
|
6d2d31928d | ||
|
|
f5156f3df6 | ||
|
|
554160db15 | ||
|
|
d8bd9b0515 | ||
|
|
27b75103ca | ||
|
|
69e01862b7 | ||
|
|
91f46b1291 | ||
|
|
9de3774715 | ||
|
|
4dbe836dfa | ||
|
|
322cc5a013 | ||
|
|
7cc5243130 | ||
|
|
ba549bd559 | ||
|
|
84be82c670 | ||
|
|
acb42982b7 | ||
|
|
3370c51b35 | ||
|
|
dcfed03702 | ||
|
|
e7dd74e4b1 | ||
|
|
19b53c76da | ||
|
|
95b40ad1d8 | ||
|
|
0efb2215e4 | ||
|
|
0c8f951d8f | ||
|
|
0bb4ef0bd9 | ||
|
|
f93a863f5f | ||
|
|
f263843c5f | ||
|
|
503202376a | ||
|
|
ca70c6a205 | ||
|
|
7d5fba8416 | ||
|
|
3a85b671a1 | ||
|
|
1083cab972 | ||
|
|
7677650b39 | ||
|
|
1f2087190e | ||
|
|
59fadee9e0 | ||
|
|
4a3825c302 | ||
|
|
52e74c241f | ||
|
|
3fa69c1852 | ||
|
|
b3074f854e | ||
|
|
95c5128d9f | ||
|
|
dc17006b16 | ||
|
|
e4a4c230fe | ||
|
|
f56a4450f3 | ||
|
|
913db3b958 | ||
|
|
7de23f86b1 | ||
|
|
35566f5ea5 | ||
|
|
34579974c3 | ||
|
|
c6f19ea0a4 | ||
|
|
64ab955ad7 | ||
|
|
4fdf496cac | ||
|
|
6497e6397d | ||
|
|
d8bbe2fcce | ||
|
|
b6cc44a956 | ||
|
|
0105c831f1 | ||
|
|
d40f96ac65 | ||
|
|
69135709ac | ||
|
|
612a9d012c | ||
|
|
2ad014faf4 | ||
|
|
f3a59e19d8 | ||
|
|
17283c86a3 | ||
|
|
945943a849 | ||
|
|
34c69785d0 | ||
|
|
d5ea4f9b1a | ||
|
|
191009372b | ||
|
|
39faddc74d | ||
|
|
5d1623b98f | ||
|
|
af0dc42df3 | ||
|
|
c18705fae3 | ||
|
|
22973899b8 | ||
|
|
f172e92098 | ||
|
|
e1ff657c78 | ||
|
|
3e6cd3ff34 | ||
|
|
f8680724f8 | ||
|
|
30c76976fc | ||
|
|
f0f020d9d2 | ||
|
|
17a13f0f83 | ||
|
|
ec441b16f1 | ||
|
|
5239f2edad | ||
|
|
cd751a64cb | ||
|
|
6d9ff3d248 | ||
|
|
d97d9980dd | ||
|
|
4ad4d6d10d | ||
|
|
82731ee86c | ||
|
|
04bdfa17f7 | ||
|
|
7a5759de4b | ||
|
|
e29dcbf8eb | ||
|
|
882f90b5ff | ||
|
|
469451d5dd | ||
|
|
af33c2dea7 | ||
|
|
d076ab4d6d | ||
|
|
e66ed8eadb | ||
|
|
05e1c00cd1 | ||
|
|
ca95f25639 | ||
|
|
95cde55a7f | ||
|
|
8756c0cbe1 | ||
|
|
86c6b09814 | ||
|
|
6ce27a7f87 | ||
|
|
7addb15be5 | ||
|
|
7b3a962498 | ||
|
|
41bba7e780 | ||
|
|
419b7d1d5c | ||
|
|
6d8b4a7ec0 | ||
|
|
84963e198e | ||
|
|
408e9946af | ||
|
|
43f49f8917 | ||
|
|
b6161c431b | ||
|
|
a236a619ad | ||
|
|
cdbd3d7d84 | ||
|
|
8efc880b77 | ||
|
|
4bade7e13a | ||
|
|
53099bbfd1 | ||
|
|
7d1d02bf3b | ||
|
|
4f477ec6d2 | ||
|
|
0a4d6fe09b | ||
|
|
8640bd5ee6 | ||
|
|
19a6a30fe2 | ||
|
|
23b6974386 | ||
|
|
103ee966f4 | ||
|
|
6100a23e80 | ||
|
|
9f7f387540 | ||
|
|
307357df70 | ||
|
|
bd903d8e8f | ||
|
|
3db6d5a458 | ||
|
|
4330da232c | ||
|
|
157dd44df0 | ||
|
|
460e60063c | ||
|
|
ec601a3381 | ||
|
|
2156c6cd7a | ||
|
|
13811c06ee | ||
|
|
230d40daa0 | ||
|
|
45aba61ac8 | ||
|
|
2adeadfd73 | ||
|
|
477e689c74 | ||
|
|
00e8f2271a | ||
|
|
9442df0cf8 | ||
|
|
d9de33820f | ||
|
|
f13fbe4398 | ||
|
|
811655bc98 | ||
|
|
0760bfaf7b | ||
|
|
fa3ee4205d | ||
|
|
7f4627356b | ||
|
|
a068b82671 | ||
|
|
177cd52039 | ||
|
|
72d4da0095 | ||
|
|
d4ddc2f9da | ||
|
|
1ab6186eaa | ||
|
|
0ea442ca36 | ||
|
|
e55dc2213a | ||
|
|
05f79c1c01 | ||
|
|
8569e1c18b | ||
|
|
2b1d4651fb | ||
|
|
c53a3d5cb4 | ||
|
|
014d2946b2 | ||
|
|
26b0c43cc4 | ||
|
|
4b4e6e1732 | ||
|
|
d0686ada83 | ||
|
|
c43285f6ac | ||
|
|
3947e90b36 | ||
|
|
916935b8d0 | ||
|
|
229606fcc5 | ||
|
|
23ceda5ad9 | ||
|
|
12e66f5a96 | ||
|
|
371a7552f5 | ||
|
|
641955a1ec | ||
|
|
f97538a399 | ||
|
|
7c8758dc26 | ||
|
|
da7db04c0e | ||
|
|
28ef5164ce | ||
|
|
d1f9563e1f | ||
|
|
70a2dbb4bb | ||
|
|
c43e7cdbdc | ||
|
|
931967353e | ||
|
|
69f095687d | ||
|
|
7b10ec26a3 | ||
|
|
82c85566dc | ||
|
|
c89d7b5b18 | ||
|
|
e8e82d9760 | ||
|
|
9817ccebcf | ||
|
|
ad522cd798 | ||
|
|
fedc946886 | ||
|
|
c3458ec59f | ||
|
|
2f09bb468e | ||
|
|
2279e18329 | ||
|
|
16e519430a | ||
|
|
0ec5b8d6dd | ||
|
|
1029c63a20 | ||
|
|
9e43540dfa | ||
|
|
3c7b3faa7f | ||
|
|
4855584de9 | ||
|
|
f67c86cb39 | ||
|
|
779a906d97 | ||
|
|
b91d7f314b | ||
|
|
3703a1c36c | ||
|
|
03fd311bfe | ||
|
|
7e78d6a92b | ||
|
|
71f7a3e902 | ||
|
|
84abe257f1 | ||
|
|
133ff4914d | ||
|
|
ba4df23bff | ||
|
|
14c9161268 | ||
|
|
236e9562fd | ||
|
|
a6409dcd27 | ||
|
|
cfd68f9f2e | ||
|
|
2cfd5754ca | ||
|
|
f81c1afde7 | ||
|
|
f7a7debd9d | ||
|
|
af56ebb04e | ||
|
|
6483b8c138 | ||
|
|
9702647044 | ||
|
|
3b2192a046 | ||
|
|
b864911e18 | ||
|
|
9e0506cb48 | ||
|
|
a0000b9489 | ||
|
|
df3fac4e5e | ||
|
|
8a36f55439 | ||
|
|
ab253744f8 | ||
|
|
fff1eaba45 | ||
|
|
eafb7b979d | ||
|
|
9e22bf39cc | ||
|
|
fc6691ce5b | ||
|
|
598dc86ca5 | ||
|
|
3e2bfc35e3 | ||
|
|
6658ad8618 | ||
|
|
759ccdbee2 | ||
|
|
635060a02d | ||
|
|
a128e7e7ab | ||
|
|
3cb69b8035 | ||
|
|
7dc58bb330 | ||
|
|
8bd0a62cb3 | ||
|
|
b25bec53d8 | ||
|
|
8a7923c974 | ||
|
|
3ee81cbee0 | ||
|
|
4b744337fe | ||
|
|
8d7d2f7a44 | ||
|
|
24bf1dbffb | ||
|
|
c1890bb126 | ||
|
|
a4a570896a | ||
|
|
0594034ee6 | ||
|
|
396e376f49 | ||
|
|
fca9eae0fd | ||
|
|
f0d9bdd901 | ||
|
|
c185d5b0b5 | ||
|
|
6ece2a3449 | ||
|
|
682d52441d | ||
|
|
c2c0c81f1c | ||
|
|
fe23907eb3 | ||
|
|
e2bf8a8a11 | ||
|
|
3f0136ae7c | ||
|
|
9f992409c7 | ||
|
|
cd53ed16e9 | ||
|
|
cc56edc91d | ||
|
|
25eb4b3547 | ||
|
|
c5eb112f5a | ||
|
|
8d904f415a | ||
|
|
c34173ca6e | ||
|
|
aa292ac6b8 | ||
|
|
c36227e2fc | ||
|
|
a406e0416f | ||
|
|
215cc5e71d | ||
|
|
0e72acee10 | ||
|
|
000ed3175d | ||
|
|
2f6bae4e2a | ||
|
|
0fefe11bfd | ||
|
|
2dbb1bbbea | ||
|
|
a586a1d525 | ||
|
|
4724101e75 | ||
|
|
1b921cd533 | ||
|
|
fcf3786fc5 | ||
|
|
d78f75aa60 | ||
|
|
56056cf10e | ||
|
|
5fd9b20213 | ||
|
|
076cdae3fd | ||
|
|
6543c7c26f | ||
|
|
3035c8af30 | ||
|
|
3cbd647dad | ||
|
|
4efcbee772 | ||
|
|
bb59cf94e9 | ||
|
|
96436814f5 | ||
|
|
e8763e936d | ||
|
|
c41a6b87b8 | ||
|
|
54395a7252 | ||
|
|
4322b8b932 | ||
|
|
f444af825f | ||
|
|
0d0e7f774e | ||
|
|
30ed27ae5c | ||
|
|
b7283487b2 | ||
|
|
551f7dc05a | ||
|
|
1b485770b6 | ||
|
|
50e18f84c2 | ||
|
|
9eab96090d | ||
|
|
737a741a54 | ||
|
|
46253039df | ||
|
|
2f5b6a115d | ||
|
|
05d63fcbe6 | ||
|
|
ae5bc76123 | ||
|
|
b70e92effb | ||
|
|
2a9b967d2d | ||
|
|
459fec56db | ||
|
|
bfdd6f36e2 | ||
|
|
432e4b7f0a | ||
|
|
39cb9c425c | ||
|
|
dff1ae0fb4 | ||
|
|
2943624439 | ||
|
|
94064e526a | ||
|
|
95cac4dfb9 | ||
|
|
46fb6a21ee | ||
|
|
3d6ca973c4 | ||
|
|
fc03f4c87a | ||
|
|
502ec2a56f | ||
|
|
66d5c3f620 | ||
|
|
220500efbb | ||
|
|
d29c5eabbb | ||
|
|
979d7c5625 | ||
|
|
4e828199c8 | ||
|
|
61c84c8e01 | ||
|
|
30be5e33d7 | ||
|
|
b1c524d4a3 | ||
|
|
7c33c7f7da | ||
|
|
7846c23edd | ||
|
|
6c0dd8543d | ||
|
|
70c082a1b1 | ||
|
|
02cda1e611 | ||
|
|
a1c82eaea6 | ||
|
|
9eda710538 | ||
|
|
a87a2d0b71 | ||
|
|
6e2f4d85a3 | ||
|
|
511727fdfa | ||
|
|
a86c7c767a | ||
|
|
da88d8f17f | ||
|
|
dbd3705441 | ||
|
|
8d2f526ee7 | ||
|
|
b075a73222 | ||
|
|
eb5387ca38 | ||
|
|
1eaef94c71 | ||
|
|
e1903edd04 | ||
|
|
0b6b8ced92 | ||
|
|
cc6ce72f6e | ||
|
|
857a384d8b | ||
|
|
13dd88b7ad | ||
|
|
e85cdc8c9f | ||
|
|
1760740a4c | ||
|
|
daf40fde82 | ||
|
|
e909b8199b | ||
|
|
ec089faf3a | ||
|
|
9fcb30ac33 | ||
|
|
cb92579461 | ||
|
|
0327000f8d | ||
|
|
3a91c87c73 | ||
|
|
db5b5d321b | ||
|
|
76b7e7408a | ||
|
|
324e5d0258 | ||
|
|
d997bbc081 | ||
|
|
1c21d4f356 | ||
|
|
5f574cf283 | ||
|
|
92f1e6da1e | ||
|
|
24aa3c781b | ||
|
|
32bd6109e3 | ||
|
|
52442017e2 | ||
|
|
278454287c | ||
|
|
5ded8fb400 | ||
|
|
24730e7ad6 | ||
|
|
016a780632 | ||
|
|
6d89638ca4 | ||
|
|
fdc091319b | ||
|
|
960c8745d9 | ||
|
|
134b09dba5 | ||
|
|
76b93274e8 | ||
|
|
ea455323d8 | ||
|
|
1855f84fe0 | ||
|
|
323d996d5f | ||
|
|
1b858393c5 | ||
|
|
ca88c5b41c | ||
|
|
7e1470ea46 | ||
|
|
f98d0bbc1f | ||
|
|
2a34022619 | ||
|
|
57f879a6ba | ||
|
|
d4ba09c753 | ||
|
|
6c3a8448cf | ||
|
|
d4e1c1b109 | ||
|
|
a1d5120e58 | ||
|
|
724e1ea97e | ||
|
|
6f8067ffd3 | ||
|
|
f38386d164 | ||
|
|
d66829702f | ||
|
|
36b50436d7 | ||
|
|
33dd747ec7 | ||
|
|
d8e14d9993 | ||
|
|
f61b9f7964 | ||
|
|
91cdc76414 | ||
|
|
a1379f61da | ||
|
|
a665d6de59 | ||
|
|
6a6a719ab6 | ||
|
|
84f17b7539 | ||
|
|
57141e478c | ||
|
|
6213917089 | ||
|
|
fb33c31378 | ||
|
|
79f5e736b0 | ||
|
|
0d4b6f5627 | ||
|
|
5c8f558f60 | ||
|
|
c851f9d5a3 | ||
|
|
2d74514dd0 | ||
|
|
84012e760e | ||
|
|
6baef49f9d | ||
|
|
f55d4fa73a | ||
|
|
ce00c627d4 | ||
|
|
d3c6f530e2 | ||
|
|
cf6391d51b | ||
|
|
57311d731e | ||
|
|
95d45b386f | ||
|
|
bbc8bed39c | ||
|
|
ec67b3975c | ||
|
|
e9967c32e6 | ||
|
|
493a213d41 | ||
|
|
f65dbee74b | ||
|
|
f51fd1267f | ||
|
|
711f3f69da | ||
|
|
24f4cbbb27 | ||
|
|
307a3e078e | ||
|
|
d31265895d | ||
|
|
6e35a879a3 | ||
|
|
9c2a3b8a82 | ||
|
|
916fab7d4b | ||
|
|
3163ef87c6 | ||
|
|
1934181b52 | ||
|
|
1b815a7d96 | ||
|
|
4e0a08106d | ||
|
|
e8cc739fbd | ||
|
|
fc57cbfb49 | ||
|
|
7522fec044 | ||
|
|
237dabb907 | ||
|
|
3686048ab6 | ||
|
|
2bf4c5d7e7 | ||
|
|
051d80b2f3 | ||
|
|
adaa1e856c | ||
|
|
4daa57c98e | ||
|
|
7e67b2cbb3 | ||
|
|
270d18a88a | ||
|
|
25f8a735a9 | ||
|
|
9eb672ea17 | ||
|
|
9febc762da | ||
|
|
4b742c220c | ||
|
|
9d03d441e1 | ||
|
|
ff8b249cc6 | ||
|
|
248e6ea5e7 | ||
|
|
be0afdebfd | ||
|
|
9f19d20344 | ||
|
|
aea8a32ba5 | ||
|
|
d1a4c82937 | ||
|
|
4f73812673 | ||
|
|
33150615a1 | ||
|
|
491f83c86d | ||
|
|
41f776763b | ||
|
|
65fdfac866 | ||
|
|
cb0c00bc6d | ||
|
|
ad53678c19 | ||
|
|
62097765a6 | ||
|
|
efb7280e99 | ||
|
|
bdb2a47743 | ||
|
|
c4677190be | ||
|
|
055aba189c | ||
|
|
314c3d5e78 | ||
|
|
6db03356b5 | ||
|
|
28af919b09 | ||
|
|
8f7a456a39 | ||
|
|
5b3bec1aac | ||
|
|
f2aa17c9d0 | ||
|
|
bc06b9e051 | ||
|
|
6d216af507 | ||
|
|
b2f1d9f376 | ||
|
|
a653e469f2 | ||
|
|
4f4241ba3a | ||
|
|
2cf9c68040 | ||
|
|
cc0f977d6f | ||
|
|
7879952fde | ||
|
|
4452cab987 | ||
|
|
98bd64621a | ||
|
|
c1c769ceb0 | ||
|
|
d64e55c66f | ||
|
|
76fc84be37 | ||
|
|
8cd5f5990e | ||
|
|
6ffe54d68f | ||
|
|
d78ea882c8 | ||
|
|
958802a233 | ||
|
|
00b02efdc2 | ||
|
|
50569f12f5 | ||
|
|
8aa4ceb570 | ||
|
|
a7afbf85ad | ||
|
|
8fdf3dcdb8 | ||
|
|
818c20e0cb | ||
|
|
49b2f80ded | ||
|
|
c1d4996777 | ||
|
|
fd3e6e0ee4 | ||
|
|
edc5754c68 | ||
|
|
bd75dea000 | ||
|
|
e09a0a548f | ||
|
|
15ee8b4362 | ||
|
|
f8cd602cbd | ||
|
|
97951aec15 | ||
|
|
3871c5a4a0 | ||
|
|
ab8d75b192 | ||
|
|
e135c969c9 | ||
|
|
36e7090466 | ||
|
|
f28f177c6b | ||
|
|
785973c624 | ||
|
|
9c06acff72 | ||
|
|
69f1e1753c | ||
|
|
4fabddeb47 | ||
|
|
17ff1ab372 | ||
|
|
01b88f876e | ||
|
|
0ead27a05b | ||
|
|
c9742bb6ea | ||
|
|
d50c1e3658 | ||
|
|
3a9c2a0356 | ||
|
|
b616a2b3e7 | ||
|
|
3c34096392 | ||
|
|
70e0d3b571 | ||
|
|
20ef115eb2 | ||
|
|
ae5a2396f3 | ||
|
|
8f82bf40e0 | ||
|
|
fe398de2fa | ||
|
|
a770d75e2e | ||
|
|
a330104e9b | ||
|
|
9b4c195872 | ||
|
|
11fa60d690 | ||
|
|
1214609546 | ||
|
|
d798356c19 | ||
|
|
4d6a9e4f14 | ||
|
|
8a7eaba668 | ||
|
|
1846f20f6e | ||
|
|
18c1787552 | ||
|
|
aae3cae4bb | ||
|
|
e7e4821804 | ||
|
|
9654802acc | ||
|
|
06a24fa4d0 | ||
|
|
62b1b0519a | ||
|
|
9981e84a42 | ||
|
|
9d313b4e0e | ||
|
|
ab2cb1ad1f | ||
|
|
f85b14a7f7 | ||
|
|
94c6a01420 | ||
|
|
563b550f08 | ||
|
|
aa45716ef7 | ||
|
|
846ef043d5 | ||
|
|
ce5b95f8e5 | ||
|
|
efc17983c3 | ||
|
|
7140898db9 | ||
|
|
6db253e1cc | ||
|
|
4c9d049b10 | ||
|
|
818e921192 | ||
|
|
6ea1d665bb | ||
|
|
7326ba1403 | ||
|
|
62bfa5157b | ||
|
|
43a8828430 | ||
|
|
618202cf8b | ||
|
|
9614a23506 | ||
|
|
10afdfecdd | ||
|
|
c0e08fb927 | ||
|
|
6d6bc9b050 | ||
|
|
4714fb6887 | ||
|
|
5f47810964 | ||
|
|
0f6024e055 | ||
|
|
fafc15f80c | ||
|
|
9a85ea861d | ||
|
|
9541960307 | ||
|
|
95073deb96 | ||
|
|
82b4647b95 | ||
|
|
0c770a8b37 | ||
|
|
0e4031348f | ||
|
|
5cc26762c2 | ||
|
|
b8b4853d1f | ||
|
|
fbabe27fc1 | ||
|
|
4d1554c85b | ||
|
|
ab40495d5c | ||
|
|
42ebf49f92 | ||
|
|
c5ccd88f79 | ||
|
|
dbd1b227d9 | ||
|
|
63baac3c61 | ||
|
|
7c39bb6659 | ||
|
|
4f8c5965ac | ||
|
|
900a17fc00 | ||
|
|
78f36aaa0d | ||
|
|
e064e02794 | ||
|
|
e22e5045f1 | ||
|
|
087f35482b | ||
|
|
23ff5fea28 | ||
|
|
34347ccaf5 | ||
|
|
e704eb6cef | ||
|
|
bf63423fec | ||
|
|
f6d71ed8ef | ||
|
|
3c342339a1 | ||
|
|
33463856c5 | ||
|
|
a18f4c9b1b | ||
|
|
783c7ee4c5 | ||
|
|
a0b2a692d0 | ||
|
|
a59d368101 | ||
|
|
5c36fb29ed | ||
|
|
508b8ef2e2 | ||
|
|
e94c62e5b3 | ||
|
|
b65a6c2829 | ||
|
|
c4a20d0798 | ||
|
|
9cb7ea524e | ||
|
|
0ac0eeda34 | ||
|
|
4d066b4fd2 | ||
|
|
840e321dd9 | ||
|
|
4b6963122b | ||
|
|
d5d662bc41 | ||
|
|
0b0ed56901 | ||
|
|
13e361aabc | ||
|
|
d1a26e66a7 | ||
|
|
ffe3c84e7c | ||
|
|
702c7382a7 | ||
|
|
b138d486e4 | ||
|
|
3a25d6b275 | ||
|
|
66e2f51233 | ||
|
|
8fdb048b6a | ||
|
|
fa3d98a492 | ||
|
|
d9dda44409 | ||
|
|
7368c01a8f | ||
|
|
21ac5be7ca | ||
|
|
e14a113277 | ||
|
|
66d3440675 | ||
|
|
6b6be3b03d | ||
|
|
cda8158bec | ||
|
|
332e0dc4a8 | ||
|
|
f7b4c6837b | ||
|
|
531928bf0b | ||
|
|
490c8e055b | ||
|
|
bcbf192bbc | ||
|
|
78d855c5ca | ||
|
|
1fa9aa88a8 | ||
|
|
08c77c2668 | ||
|
|
793ebe1b0f | ||
|
|
4c42acc7e1 | ||
|
|
4eb9660bfa | ||
|
|
8ed08f701d | ||
|
|
784964efad | ||
|
|
adb96e72b9 | ||
|
|
439c6f7296 | ||
|
|
e2f1ea1444 | ||
|
|
2977ceb459 | ||
|
|
e00d4e0ed8 | ||
|
|
772127d9d8 | ||
|
|
6ba45c88ec | ||
|
|
5a4040cf0b | ||
|
|
b54f580e66 | ||
|
|
a9ac69fe9c | ||
|
|
5c52b5e404 | ||
|
|
b80360b7da | ||
|
|
2753883687 | ||
|
|
ced73ffb14 | ||
|
|
672fe2dfd7 | ||
|
|
04bb6997a2 | ||
|
|
c8a8dbbbae | ||
|
|
1f9520dc78 | ||
|
|
84f8627890 | ||
|
|
a177df32b7 | ||
|
|
f25d5dd123 | ||
|
|
4cfa9e6165 | ||
|
|
0303ea7f57 | ||
|
|
2813e01e61 | ||
|
|
e3420da60f | ||
|
|
60493d30f6 | ||
|
|
6efe8e7d7c | ||
|
|
2e8409f146 | ||
|
|
ac4b2b9dfe | ||
|
|
23b6178e78 | ||
|
|
5e5d45fb0a | ||
|
|
1765b8f2cf | ||
|
|
5678562ce2 | ||
|
|
7274197da0 | ||
|
|
c79fcb380b | ||
|
|
6a98eade07 | ||
|
|
9008a65c14 | ||
|
|
4e07e4c7f3 | ||
|
|
e440d8503a | ||
|
|
e9bacff830 | ||
|
|
9cc99ffcd6 | ||
|
|
beb91271de | ||
|
|
7e9585ebc5 | ||
|
|
0c4b3f71e5 | ||
|
|
5c17ec5f01 | ||
|
|
8b4edc46a7 | ||
|
|
2b7a0a4585 | ||
|
|
1882176489 | ||
|
|
875e89e71a | ||
|
|
52520635ea | ||
|
|
aa50a9ba83 | ||
|
|
489e5111ac | ||
|
|
2d4c20af35 | ||
|
|
66fdb447f7 | ||
|
|
c801775a39 | ||
|
|
f5bb57d6a6 | ||
|
|
1071ab05db | ||
|
|
8461cf6443 | ||
|
|
bb10501f56 | ||
|
|
c4d5f657da | ||
|
|
cabb58a9aa | ||
|
|
e64ce5bb4f | ||
|
|
bc750d61d2 | ||
|
|
3150901b6e | ||
|
|
4f6745b742 | ||
|
|
bcdc323a97 | ||
|
|
4fd4cc709d | ||
|
|
0fac463144 | ||
|
|
d809dfac65 | ||
|
|
983fd70260 | ||
|
|
ea11a5274e | ||
|
|
42356c2a67 | ||
|
|
5a84ab2011 | ||
|
|
b4573e341f | ||
|
|
df252c4704 | ||
|
|
d1912f873b | ||
|
|
e525c42c7d | ||
|
|
0242322d24 | ||
|
|
ded6fafc8a | ||
|
|
4aebd678c3 | ||
|
|
afc9ed2274 | ||
|
|
d73d021e3c | ||
|
|
c8fe81e21d | ||
|
|
621f1df913 | ||
|
|
5f4274b449 | ||
|
|
4acb37156f | ||
|
|
1ca23a7479 | ||
|
|
61daf7218d | ||
|
|
dc6671fc4e | ||
|
|
f34237ebc8 | ||
|
|
aadeb3b87e | ||
|
|
1fb75c1af3 | ||
|
|
e04d28c885 | ||
|
|
6d80b3675a | ||
|
|
07d698f8dc | ||
|
|
ef158504e7 | ||
|
|
63be1ae5a9 | ||
|
|
b9ba1a4f69 | ||
|
|
e006d9b033 | ||
|
|
1538684c6c | ||
|
|
b37e83caab | ||
|
|
d11d3ab08b | ||
|
|
1144a536a5 | ||
|
|
515c753d11 | ||
|
|
0864e640ed | ||
|
|
b876e49393 | ||
|
|
fc0292bf8a | ||
|
|
a903805cd9 | ||
|
|
abab34573e | ||
|
|
fa1b94af60 | ||
|
|
81ff5d1224 | ||
|
|
5c3a8819a4 | ||
|
|
4d0a08d858 | ||
|
|
c41bdaa2b7 | ||
|
|
4bf2fc18e5 | ||
|
|
145fd8657f | ||
|
|
01b55d1d29 | ||
|
|
98b3151c5f | ||
|
|
c7eca8deb3 | ||
|
|
627b54f712 | ||
|
|
8ef7b6fc54 | ||
|
|
d83652b0fc | ||
|
|
cce32229e0 | ||
|
|
24edd83c8a | ||
|
|
268c5b6482 | ||
|
|
a66a754126 | ||
|
|
18059734ce | ||
|
|
c883e709c3 | ||
|
|
7be0bd3583 | ||
|
|
d9ab37ea58 | ||
|
|
ff075ba612 | ||
|
|
9c9294a730 | ||
|
|
2a0842b8ae | ||
|
|
3cfe45ffc2 | ||
|
|
80dc7bfc52 | ||
|
|
10f26f17ba | ||
|
|
4ba7402f28 | ||
|
|
d4da2e0d9c | ||
|
|
b180d004ba | ||
|
|
de5bd96f08 | ||
|
|
3a05b5dacc | ||
|
|
b3c4e32b68 | ||
|
|
375a48f135 | ||
|
|
1750ab92e6 | ||
|
|
8364ddd10b | ||
|
|
63043cb45d | ||
|
|
aaa6497659 | ||
|
|
4fc6fa9c8a | ||
|
|
7d0dcfb3a5 | ||
|
|
a97ea0ad63 | ||
|
|
da66a4d22f | ||
|
|
748e54d4c2 | ||
|
|
0f172595d7 | ||
|
|
5ffdbd99e8 | ||
|
|
fbe57c4c71 | ||
|
|
61726168d6 | ||
|
|
a80632ab36 | ||
|
|
893eb8b73b | ||
|
|
07a5ee7d2c | ||
|
|
c7a300be2f | ||
|
|
ef842fca89 | ||
|
|
bdbe9e1ca5 | ||
|
|
0c7f65222c | ||
|
|
a8fa644d25 | ||
|
|
cf7ccb5b8c | ||
|
|
49fdd6fc5b | ||
|
|
5e91c74304 | ||
|
|
b83e6f6e7c | ||
|
|
2687777a82 | ||
|
|
918b8036ea | ||
|
|
7ea0e4d4db | ||
|
|
622c1705aa | ||
|
|
3a08929b05 | ||
|
|
99e30d561d | ||
|
|
033a44580c | ||
|
|
4734bcfbb4 | ||
|
|
099fe6f477 | ||
|
|
889327b5f6 | ||
|
|
a2845f44ab | ||
|
|
a7477516d1 | ||
|
|
938d5828fc | ||
|
|
bf3eab453c | ||
|
|
ebab893330 | ||
|
|
4c67b3a118 | ||
|
|
d74b06f8bf | ||
|
|
c54e211147 | ||
|
|
8817cf5116 | ||
|
|
fb568513b2 | ||
|
|
b4ebfdb84a | ||
|
|
7040bd804a | ||
|
|
2f2fc17bd8 | ||
|
|
d5d4b49aaf | ||
|
|
042c4efddf | ||
|
|
01251d162c | ||
|
|
64026fde7c | ||
|
|
adcdae4abe | ||
|
|
88d138b925 | ||
|
|
2773b89815 | ||
|
|
949d93fdaa | ||
|
|
90a4303c8e | ||
|
|
d3b1972505 | ||
|
|
3807d5fbd0 | ||
|
|
e49e2021e5 | ||
|
|
84a5276ab0 | ||
|
|
1732c3b350 | ||
|
|
0f52f63863 | ||
|
|
0043e95ba7 | ||
|
|
a3f2088046 | ||
|
|
186f5553b8 | ||
|
|
d8454d9da5 | ||
|
|
318194a216 | ||
|
|
b50d2358d3 | ||
|
|
763587ffb4 | ||
|
|
8a375c12e9 | ||
|
|
11afdb51f3 | ||
|
|
e4353f4650 | ||
|
|
9d4437a7f5 | ||
|
|
493bf5ed08 | ||
|
|
93800fd834 | ||
|
|
79bc34ed76 | ||
|
|
b40ad7e87e | ||
|
|
1ab3fba212 | ||
|
|
3cd0bbc0f4 | ||
|
|
a806728e43 | ||
|
|
683037ca69 | ||
|
|
a113127df1 | ||
|
|
fecfaaf812 | ||
|
|
8df8f1f6f7 | ||
|
|
5502ca5f58 | ||
|
|
75b8cfa92e | ||
|
|
f7b23fb0e2 | ||
|
|
42f7abf2f5 | ||
|
|
08dd0e34d1 | ||
|
|
7540770dec | ||
|
|
213c5df706 | ||
|
|
578e4b2785 | ||
|
|
8f8db0c431 | ||
|
|
df7253b13e | ||
|
|
fcafd63f41 | ||
|
|
c82fdb9fa1 | ||
|
|
454c52f4ab | ||
|
|
73c69c3f93 | ||
|
|
614ec30e05 | ||
|
|
d7c07e0ed3 | ||
|
|
08bd16c1b6 | ||
|
|
4f06c72798 | ||
|
|
166fe2a4e5 | ||
|
|
b7635a71c8 | ||
|
|
6ad4bdea83 | ||
|
|
efb9a11d22 | ||
|
|
047d09bcb1 | ||
|
|
e1ca6b5181 | ||
|
|
36a2569537 | ||
|
|
10ceddfa67 | ||
|
|
929677afe0 | ||
|
|
ee4adc1363 | ||
|
|
c7b2bdfaac | ||
|
|
fde8fb960b | ||
|
|
9a43d26c60 | ||
|
|
742f603b3b | ||
|
|
a82f2a5df3 | ||
|
|
06bc5513ae | ||
|
|
47b937f880 | ||
|
|
775d27b6a9 | ||
|
|
6c838ab57c | ||
|
|
8eebd2aa67 | ||
|
|
fc78a08657 | ||
|
|
7b3cc95ab7 | ||
|
|
bd70765b7d | ||
|
|
5b424aec22 | ||
|
|
d6cc0694f0 | ||
|
|
9738515129 | ||
|
|
b05ee10f41 | ||
|
|
67d85f0f86 | ||
|
|
2ddeef761f | ||
|
|
43e0109d44 | ||
|
|
02bb41697d | ||
|
|
12cd56e3e8 | ||
|
|
72cfb70e35 | ||
|
|
40dc180b88 | ||
|
|
4529c326c6 | ||
|
|
f6660af014 | ||
|
|
a52131b574 | ||
|
|
a48d0492c8 | ||
|
|
2bba1be817 | ||
|
|
8a394fb08f | ||
|
|
693ae9e8f2 | ||
|
|
4b7b6d6cb3 | ||
|
|
9a3bdfb14b | ||
|
|
7aeddc63ac | ||
|
|
2990a1c255 | ||
|
|
91eea03b18 | ||
|
|
8702f290af | ||
|
|
d0b5b7ba03 | ||
|
|
f3d68c6f25 | ||
|
|
91100d3fac | ||
|
|
61833c32e5 | ||
|
|
1468f67b9b | ||
|
|
cb6376094c | ||
|
|
ff175e661b | ||
|
|
fe741f168a | ||
|
|
eaaf500d5e | ||
|
|
05f85b33c5 | ||
|
|
c4e0647bda | ||
|
|
6dcc1e09b9 | ||
|
|
ea03e4d34a | ||
|
|
b7a2d17e93 | ||
|
|
e1bd740249 | ||
|
|
de52c2da80 | ||
|
|
a31c6d82c9 | ||
|
|
25842894d2 | ||
|
|
83c98c2d55 | ||
|
|
fe2011742d | ||
|
|
d87b676d60 | ||
|
|
ffa6378108 | ||
|
|
f73ba895af | ||
|
|
cb2a1147f0 | ||
|
|
6702ef4a71 | ||
|
|
1d46791364 | ||
|
|
f61846dec9 | ||
|
|
4776e196da | ||
|
|
839a48b678 | ||
|
|
e203901224 | ||
|
|
76d03f7fd2 | ||
|
|
7f5e3aaaf7 | ||
|
|
5bfbae4b00 | ||
|
|
521a854635 | ||
|
|
ce15ef2db9 | ||
|
|
6d5cf89d33 | ||
|
|
b3b984f351 | ||
|
|
d5a0f1e711 | ||
|
|
67c36f3d98 | ||
|
|
8e0a29e9b5 | ||
|
|
47be879445 | ||
|
|
860f8a7906 | ||
|
|
5d9baa053a | ||
|
|
da174eae71 | ||
|
|
7fac71aa81 | ||
|
|
7d51c1140d | ||
|
|
cd198223ea | ||
|
|
300fff40e3 | ||
|
|
08abac350d | ||
|
|
a57decf8be | ||
|
|
ee95e59243 | ||
|
|
b0694bcf2c | ||
|
|
c9f6e31ca9 | ||
|
|
fe4080d59f | ||
|
|
7f6a1ad1a7 | ||
|
|
980bb35441 | ||
|
|
01df2e2dc7 | ||
|
|
ec40dd1b6f | ||
|
|
f2f8898004 | ||
|
|
3afa37c6ea | ||
|
|
8c0ce38301 | ||
|
|
cc6aa3209c | ||
|
|
76a86763dd | ||
|
|
09fb039528 | ||
|
|
174d3300c4 | ||
|
|
8b57ce1792 | ||
|
|
6c14e429eb | ||
|
|
5f200c6bc3 | ||
|
|
d52347ee1d | ||
|
|
d0d9aa4400 | ||
|
|
c3d909c818 | ||
|
|
d9e718b0e0 | ||
|
|
a7b55edb9b | ||
|
|
000479d55e | ||
|
|
7ef22f2940 | ||
|
|
a242fcfd2c | ||
|
|
73c21ae0a9 | ||
|
|
2398454838 | ||
|
|
c1ba5a30c5 | ||
|
|
2c0f847d3e | ||
|
|
7d5e95f013 | ||
|
|
9000342de8 | ||
|
|
61b47aa0de | ||
|
|
22f5c5fb74 | ||
|
|
801162d7be | ||
|
|
f81f3fb060 | ||
|
|
15792d8426 | ||
|
|
d7f345eef8 | ||
|
|
e3031462c1 | ||
|
|
47d14271ab | ||
|
|
2bf9fd6cbc | ||
|
|
19e716b522 | ||
|
|
1ee15942cc | ||
|
|
898e641256 | ||
|
|
cda4ccff2a | ||
|
|
ba274482f7 | ||
|
|
435f734d60 | ||
|
|
a5f949c4e2 | ||
|
|
9fc556864e | ||
|
|
a0645dc713 | ||
|
|
5893cd309d | ||
|
|
09c7ab1ee6 | ||
|
|
4bacae3711 | ||
|
|
8d3e536582 | ||
|
|
697cc0a79b | ||
|
|
a34ed5c02a | ||
|
|
256bb01606 | ||
|
|
1de535363d | ||
|
|
24d9011939 | ||
|
|
6284bdc98f | ||
|
|
e7351b1bb8 | ||
|
|
b3ee89c6e5 | ||
|
|
3f49492ccf | ||
|
|
ad700b45d0 | ||
|
|
74923b4575 | ||
|
|
81199e7ee0 | ||
|
|
ccca1b0bea | ||
|
|
ba1ced5e08 | ||
|
|
558466d506 | ||
|
|
b424ef9ebb | ||
|
|
69f5fd86a4 | ||
|
|
f9ba9ae912 | ||
|
|
b33fec6236 | ||
|
|
70e12485aa | ||
|
|
b2b7674b59 | ||
|
|
8fa175f36d | ||
|
|
95fbc904d1 | ||
|
|
ce37a8dda2 | ||
|
|
e0499c9552 | ||
|
|
4825f2510f | ||
|
|
7a12134795 | ||
|
|
66adfa074b | ||
|
|
9d201eb9c6 | ||
|
|
789fc0a7e0 | ||
|
|
9e309132f8 | ||
|
|
88923173c2 | ||
|
|
7b55863418 | ||
|
|
38d5fad4e5 | ||
|
|
4d1357568b | ||
|
|
ccc190f991 | ||
|
|
0a9f880fb4 | ||
|
|
b8faf54f0b | ||
|
|
888507f7ba | ||
|
|
29866092de | ||
|
|
36fc2c83f2 | ||
|
|
5e777b3c51 | ||
|
|
5690c48863 | ||
|
|
8ab3363097 | ||
|
|
f6861ca5f5 | ||
|
|
3bb58be2b5 | ||
|
|
409c96e571 | ||
|
|
d681fa6cba | ||
|
|
7c3d8356c4 | ||
|
|
a8842da50a | ||
|
|
ff29b84146 | ||
|
|
ab12a4eb39 | ||
|
|
c3fd0889e2 | ||
|
|
c62532a665 | ||
|
|
ca63d6ba1c | ||
|
|
a1f496b019 | ||
|
|
da421438cd | ||
|
|
7f723ef2bf | ||
|
|
3cf39dace0 | ||
|
|
021ad4f12c | ||
|
|
36edf447e7 | ||
|
|
ea2273aef4 | ||
|
|
251aa22c4c | ||
|
|
541710147a | ||
|
|
a197ca4cf7 | ||
|
|
775c36bb65 | ||
|
|
1953b95c57 | ||
|
|
542a33952f | ||
|
|
1819712667 | ||
|
|
69a596fdff | ||
|
|
4f88b93495 | ||
|
|
a388052e2a | ||
|
|
8b81ea3b6f | ||
|
|
b913de5928 | ||
|
|
4e551cde66 | ||
|
|
b681cbd47f | ||
|
|
551253b4e0 | ||
|
|
4ad9166b5a | ||
|
|
8487255c33 | ||
|
|
2792d4ea1e | ||
|
|
95180a850f | ||
|
|
56ee7a0abd | ||
|
|
d0a04be825 | ||
|
|
2cbf287998 | ||
|
|
054cf98754 | ||
|
|
a95fbfe271 | ||
|
|
17ce02a87c | ||
|
|
4dc5e0378f | ||
|
|
c33797ff84 | ||
|
|
f242b40d0a | ||
|
|
5f916f5a9c | ||
|
|
6edb525540 | ||
|
|
0c04d5b2ab | ||
|
|
301852fd87 | ||
|
|
0e8df7d633 | ||
|
|
e4155e0e16 | ||
|
|
2c4dbe6e68 | ||
|
|
a99b96e36e | ||
|
|
0889467c7b | ||
|
|
d141e228de | ||
|
|
9b15c42801 | ||
|
|
a781b631e1 | ||
|
|
08af5c8e09 | ||
|
|
93e8cca02f | ||
|
|
a8e9a1fbe5 | ||
|
|
54eb30f3db | ||
|
|
c08a1adc9b | ||
|
|
cd951ad396 | ||
|
|
33793d878b | ||
|
|
357955015d | ||
|
|
d6d94adab0 | ||
|
|
099cc9f727 | ||
|
|
61f8d6f171 | ||
|
|
a7af4685f1 | ||
|
|
2cebed4f77 | ||
|
|
3f2a371599 | ||
|
|
a3ca3d9179 | ||
|
|
86ace1a4af | ||
|
|
1abdf62045 | ||
|
|
9e2a96675d | ||
|
|
f32876708a | ||
|
|
84e0e7e020 | ||
|
|
38cddff6e9 | ||
|
|
f1aba8115b | ||
|
|
0db5ff55fd | ||
|
|
7421b0de6c | ||
|
|
6c275c30a7 | ||
|
|
91f1d793e9 | ||
|
|
cddfd04a7f | ||
|
|
7fa94c33bf | ||
|
|
30dd20dc7b | ||
|
|
339c0d3dc7 | ||
|
|
2304d63bb3 | ||
|
|
36014f9fe5 | ||
|
|
351383dfa4 | ||
|
|
defad94f5a | ||
|
|
a0517478e3 | ||
|
|
7f4e68f21c | ||
|
|
c0a425c26d | ||
|
|
e756859b16 | ||
|
|
174bc017ad | ||
|
|
4a9fb0212f | ||
|
|
212848409f | ||
|
|
e45ee0eb81 | ||
|
|
3b8e37de58 | ||
|
|
c2e8cc9bd6 | ||
|
|
ec81d29580 | ||
|
|
c4de0f3b17 | ||
|
|
965d41990e | ||
|
|
d96dba336b | ||
|
|
a7e1b4653e | ||
|
|
e38b42bc21 | ||
|
|
36bd502292 | ||
|
|
594bf3dfc8 | ||
|
|
6d30ccfc63 | ||
|
|
1b79f513a3 | ||
|
|
74825a0f57 | ||
|
|
4a23d12df2 | ||
|
|
7f117574ab | ||
|
|
f91474c2f8 | ||
|
|
2a081aac2b | ||
|
|
9b10f31fb3 | ||
|
|
63ad7b8d34 | ||
|
|
86baaab2e9 | ||
|
|
3e66d23367 | ||
|
|
609b5588fa | ||
|
|
798072b8ba | ||
|
|
d950a58613 | ||
|
|
4c68e6fe41 | ||
|
|
914ce77b50 | ||
|
|
d09989a4ed | ||
|
|
6999a4e3a9 | ||
|
|
069541f374 | ||
|
|
49b9b28c99 | ||
|
|
b274482125 | ||
|
|
b766a55b0a | ||
|
|
b8057b7ddb | ||
|
|
98266f47d6 | ||
|
|
7b83979e10 | ||
|
|
79cdcca2d2 | ||
|
|
4c0d00640b | ||
|
|
ad87b7c4a5 | ||
|
|
74f36b264b | ||
|
|
2df43b6c5d | ||
|
|
73f80624b2 | ||
|
|
fe2a4b7a4a | ||
|
|
affdf7241f | ||
|
|
1c5a3e6698 | ||
|
|
db88212a64 | ||
|
|
43074464ac | ||
|
|
1e7afa9da0 | ||
|
|
e985887739 | ||
|
|
d5287256e0 | ||
|
|
6bb2adaf45 | ||
|
|
64fcd56998 | ||
|
|
7d3a56a870 | ||
|
|
48dd3b8506 | ||
|
|
734bbff04d | ||
|
|
5adde12dff | ||
|
|
5079e15401 | ||
|
|
9196ed1e9f | ||
|
|
c69a2406ad | ||
|
|
47197aa495 | ||
|
|
dbd6303829 | ||
|
|
1f8d2531cc | ||
|
|
d2de2aef07 | ||
|
|
e22b4e8430 | ||
|
|
af0b7e4701 | ||
|
|
acef386403 | ||
|
|
15ba9b6295 | ||
|
|
2f47cf0be5 | ||
|
|
774106fc26 | ||
|
|
1b0ff9f5be | ||
|
|
dfaa6895ae | ||
|
|
cb52a299cc | ||
|
|
0ac0851ef3 | ||
|
|
c0f177548a | ||
|
|
8923c9e5af | ||
|
|
e609ebe3f9 | ||
|
|
8617c3d359 | ||
|
|
61e97e5e6f | ||
|
|
521e44bd54 | ||
|
|
18e91c480b | ||
|
|
9d2e6e1c31 | ||
|
|
eb02100d68 | ||
|
|
ee18d60644 | ||
|
|
612600278a | ||
|
|
ea8adf39c2 | ||
|
|
f7f61e0f85 | ||
|
|
a7bb249070 | ||
|
|
dfe7dfcfd3 | ||
|
|
7223a36a71 | ||
|
|
2423d197cd | ||
|
|
2582791501 | ||
|
|
3a08c92433 | ||
|
|
694d8fd6fb | ||
|
|
369bb9166e | ||
|
|
5f1e5ef206 | ||
|
|
5d04fd0d97 | ||
|
|
d05b5e40df | ||
|
|
0dd436ac54 | ||
|
|
d5359fb9ba | ||
|
|
72c29aca6a | ||
|
|
32216a334d | ||
|
|
603d55114b | ||
|
|
9d18db9cae | ||
|
|
d14c6ea202 | ||
|
|
7be5fe925a | ||
|
|
8f43d7fa34 | ||
|
|
b6e9bcee3c | ||
|
|
2dbef704e9 | ||
|
|
74a4691f29 | ||
|
|
084a87ed61 | ||
|
|
657b53ae0b | ||
|
|
17cb1226c6 | ||
|
|
02e281e465 | ||
|
|
4e6d0c9c69 | ||
|
|
81d069209c | ||
|
|
63e3c82f9d | ||
|
|
e8f2f7b24e | ||
|
|
b7f7e607c1 | ||
|
|
ac4108b05b | ||
|
|
14287b12ae | ||
|
|
20ce5f6967 | ||
|
|
1a296cbd4e | ||
|
|
642276c90c | ||
|
|
e4b2fd87de | ||
|
|
dacde72456 | ||
|
|
7e66af05ff | ||
|
|
b6bb5b79af | ||
|
|
f0486eb820 | ||
|
|
cdc2847b96 | ||
|
|
1d996d9ed9 | ||
|
|
e06ac87c0d | ||
|
|
0c19fcd79f | ||
|
|
02fe3d1b99 | ||
|
|
95b90a59dc | ||
|
|
fe7852b64e | ||
|
|
f87cb4231c | ||
|
|
7484fb6120 | ||
|
|
430d4e5f6e | ||
|
|
6f6791c1b5 | ||
|
|
bc11ae7245 | ||
|
|
de228bdb4b | ||
|
|
25fb199ba0 | ||
|
|
d0795f5770 | ||
|
|
fbb8c8e80c | ||
|
|
76610f1e72 | ||
|
|
618d74cd67 | ||
|
|
59700cb477 | ||
|
|
fc1a136448 | ||
|
|
42ef43bdf6 | ||
|
|
f53b3c2e7b | ||
|
|
22a0e3fe9c | ||
|
|
e0601bab3d | ||
|
|
69369b02ea | ||
|
|
966b9fac49 | ||
|
|
e2a86dd803 | ||
|
|
1b88cfd053 | ||
|
|
6412adcfa7 | ||
|
|
76de8f55f2 | ||
|
|
ae43b83162 | ||
|
|
8d81c8c1e0 | ||
|
|
1e173524b5 | ||
|
|
490418d359 | ||
|
|
51ef4d82f9 | ||
|
|
e522920d49 | ||
|
|
47be554aff | ||
|
|
f44b2a63b0 | ||
|
|
8d4b893658 | ||
|
|
7e3c61eb41 | ||
|
|
bb396685ab | ||
|
|
8ef0ea8aea | ||
|
|
34c766dc2b | ||
|
|
a30fa710ad | ||
|
|
fa01884350 | ||
|
|
eae9ad6f8b | ||
|
|
be533fa66a | ||
|
|
254b061921 | ||
|
|
cefa03f45b | ||
|
|
b67203b421 | ||
|
|
e14c4d0683 | ||
|
|
4ed96b16f4 | ||
|
|
932c86bb3b | ||
|
|
590fd53dd4 | ||
|
|
8e7dc5e86f | ||
|
|
e13ce3140b | ||
|
|
2ebb43b613 | ||
|
|
863a70b8fc | ||
|
|
89a4b6fee5 | ||
|
|
0405c945e2 | ||
|
|
5293ea70ae | ||
|
|
b5cbc97333 | ||
|
|
a867452927 | ||
|
|
b13ca0d077 | ||
|
|
c6f4d6d8bd | ||
|
|
8723aa097e | ||
|
|
97e6bc2be3 | ||
|
|
2c2555fad9 | ||
|
|
f4f69a030a | ||
|
|
86f66f4d78 | ||
|
|
b4e2b69086 | ||
|
|
1a1a59a14e | ||
|
|
1687e8d26f | ||
|
|
4b8252e001 | ||
|
|
f505ff03e4 | ||
|
|
ff8e282c43 | ||
|
|
e39cb160f9 | ||
|
|
76ce0c3540 | ||
|
|
f7047bbf51 | ||
|
|
c3a53cefb0 | ||
|
|
a88153954e | ||
|
|
4732085421 | ||
|
|
e4e6a00fe4 | ||
|
|
700e10bc0e | ||
|
|
2a4c193601 | ||
|
|
d3fa289f27 | ||
|
|
1534a07ded | ||
|
|
a4e92694ba | ||
|
|
035da9e5d7 | ||
|
|
fed6f4ab8a | ||
|
|
d7c42f3c98 | ||
|
|
ad852161f3 | ||
|
|
e9b2d6a594 | ||
|
|
f9d2fe710d | ||
|
|
a4a1cd42db | ||
|
|
69e14dcb2d | ||
|
|
e2673894b4 | ||
|
|
852b16c972 | ||
|
|
5796c28391 | ||
|
|
b6095e29d7 | ||
|
|
f778957caf | ||
|
|
47f8da6532 | ||
|
|
0b3f2a55df | ||
|
|
13ff2bd8c4 | ||
|
|
c690a64462 | ||
|
|
d808bfe400 | ||
|
|
1b30078c09 | ||
|
|
0278875e03 | ||
|
|
d0ccf28678 | ||
|
|
5023255ebc | ||
|
|
545376875a | ||
|
|
a9fe77b62e | ||
|
|
b42d8799b4 | ||
|
|
a42e197634 | ||
|
|
fc32c85608 | ||
|
|
dabd431b1f | ||
|
|
85b4817a1e | ||
|
|
84c6113271 | ||
|
|
9506f8c38e | ||
|
|
d330d890c0 | ||
|
|
c6369b1c5a | ||
|
|
bfa0f9d911 | ||
|
|
154cb2db83 | ||
|
|
37ecfa6b67 | ||
|
|
99ba2fb358 | ||
|
|
85ebde29dc | ||
|
|
0876f45503 | ||
|
|
2fae6890c2 | ||
|
|
34f9961857 | ||
|
|
515f0c5089 | ||
|
|
5a11551b4d | ||
|
|
49bf99588b | ||
|
|
231110fb61 | ||
|
|
4c30bf80ce | ||
|
|
f8afefa2c1 | ||
|
|
89bb2d0ffe | ||
|
|
b5d5d98645 | ||
|
|
89f394ab86 | ||
|
|
cbaa4e03b3 | ||
|
|
50539465b9 | ||
|
|
be08bcb22b | ||
|
|
dcd92a894e | ||
|
|
6336eeb568 | ||
|
|
6b18cbda1f | ||
|
|
cf023ea557 | ||
|
|
51a804a80f | ||
|
|
1a33b1c574 | ||
|
|
67e2e4d415 | ||
|
|
8c2efa707a | ||
|
|
87abc6e4a2 | ||
|
|
0ea017c53d | ||
|
|
b9c7510b58 | ||
|
|
01e7caf65a | ||
|
|
1cfeb730c3 | ||
|
|
a3b90a08b6 | ||
|
|
31571be71e | ||
|
|
661fc45106 | ||
|
|
da64dee3e0 | ||
|
|
cb00f5da79 | ||
|
|
e1df41c209 | ||
|
|
3b64748427 | ||
|
|
70cef68eeb | ||
|
|
c5f64d2988 | ||
|
|
4eb068613d | ||
|
|
d774430ec2 | ||
|
|
d24a982757 | ||
|
|
d74c70a57c | ||
|
|
a6f0f78588 | ||
|
|
e6d9991581 | ||
|
|
ec8dbddcfb | ||
|
|
bc699f17d9 | ||
|
|
832df41130 | ||
|
|
5709681076 | ||
|
|
858baf0c2c | ||
|
|
e4b3e23769 | ||
|
|
8ce05796da | ||
|
|
7f8c6d8cca | ||
|
|
75ba040531 | ||
|
|
faa78e1c04 | ||
|
|
b264d3be3c | ||
|
|
80d7e84e5d | ||
|
|
4e37610f21 | ||
|
|
78030e4a31 | ||
|
|
b01c842d7c | ||
|
|
c56c10bced | ||
|
|
b0ccbc36d9 | ||
|
|
9cdfc3409d | ||
|
|
fc851f542a | ||
|
|
7530abd581 | ||
|
|
a6594a9ae3 | ||
|
|
62019f57e9 | ||
|
|
41443bb7f9 | ||
|
|
8b5f7d98f6 | ||
|
|
6fea6f730d | ||
|
|
ad42a39a43 | ||
|
|
ed9cfedbf3 | ||
|
|
36510d8451 | ||
|
|
501a6eee69 | ||
|
|
39cd8465f4 | ||
|
|
d3c0d2ebb1 | ||
|
|
911c0e45dc | ||
|
|
7628ee1e05 | ||
|
|
de3e5e1c39 | ||
|
|
27627b4f74 | ||
|
|
469f8ac31d | ||
|
|
c8d296ea0e | ||
|
|
c6adbe939d | ||
|
|
b4464ab0a3 | ||
|
|
bf7d57c560 | ||
|
|
0e59819af4 | ||
|
|
1cc4f56025 | ||
|
|
1d03e0822e | ||
|
|
b722da642a | ||
|
|
0aa1d1caa0 | ||
|
|
da28e1dd44 | ||
|
|
d223a286c0 | ||
|
|
7916a7fa07 | ||
|
|
ee81895e1e | ||
|
|
6ac4384769 | ||
|
|
99fababf0b | ||
|
|
c85f1b20ca | ||
|
|
51f43842cf | ||
|
|
8015ba1d64 | ||
|
|
cfa69cf35a | ||
|
|
dced1932b3 | ||
|
|
79a08f96c5 | ||
|
|
f5d98c1db6 | ||
|
|
df4273e986 | ||
|
|
5d79690260 | ||
|
|
6c9e16d31a | ||
|
|
f0fc50d5a9 | ||
|
|
7a4a4389fa | ||
|
|
131889cdfb | ||
|
|
bed14d5c02 | ||
|
|
d3c831a0a2 | ||
|
|
0007c12dea | ||
|
|
049077f13b | ||
|
|
e17c69f89c | ||
|
|
4b24f32d6c | ||
|
|
f404e31e30 | ||
|
|
7455b26ab2 | ||
|
|
ee3259a74d | ||
|
|
391ba67ad5 | ||
|
|
54f8c68151 | ||
|
|
4a2e1897a6 | ||
|
|
076616bfb9 | ||
|
|
a9dd78f622 | ||
|
|
d16bdafaf0 | ||
|
|
4f126c5292 | ||
|
|
7b958a20fd | ||
|
|
4519071718 | ||
|
|
0108b4724e | ||
|
|
bb08b39c71 | ||
|
|
1908ac428b | ||
|
|
dfc453c1d1 | ||
|
|
9fa6289093 | ||
|
|
6f92ce0fa8 | ||
|
|
cde2c9137f | ||
|
|
120524ae00 | ||
|
|
7bb73f45a5 | ||
|
|
2d0f563dfe | ||
|
|
cfe3c69f00 | ||
|
|
c266d2ca0d | ||
|
|
85fc696975 | ||
|
|
9bf8bed0c3 | ||
|
|
c4d55f6ba4 | ||
|
|
766d7cbd3a | ||
|
|
8e0e1bd58d | ||
|
|
a471ccc95a | ||
|
|
daac8c4824 | ||
|
|
59c22a5626 | ||
|
|
5154f27f72 | ||
|
|
5f7279eb85 | ||
|
|
ce67f593f6 | ||
|
|
556ea57f37 | ||
|
|
a4257b619a | ||
|
|
8479c8afbf | ||
|
|
eba012b965 | ||
|
|
66e53e6804 | ||
|
|
c8aa8b55f6 | ||
|
|
900e3905c0 | ||
|
|
088490721d | ||
|
|
a40b99aae0 | ||
|
|
b9646446f8 | ||
|
|
4e36b35039 | ||
|
|
d412ee6042 | ||
|
|
67848e3333 | ||
|
|
4d79c6e235 | ||
|
|
bc99d9d196 | ||
|
|
e1fc5863c2 | ||
|
|
f0791149e6 | ||
|
|
297b032bdc | ||
|
|
98180c175d | ||
|
|
46e8a436cb | ||
|
|
dc2cf8ecfc | ||
|
|
fd69ebfd1f | ||
|
|
03979fdc51 | ||
|
|
2c98e91276 | ||
|
|
3270120d16 | ||
|
|
77a7efc920 | ||
|
|
de604e744e | ||
|
|
24c0a833bd | ||
|
|
45f011c63c | ||
|
|
bc86201b44 | ||
|
|
b82af9fff3 | ||
|
|
3a1e74a306 | ||
|
|
e4cca92910 | ||
|
|
102220834c | ||
|
|
24d744b94c | ||
|
|
1df6229e99 | ||
|
|
c23e98ff83 | ||
|
|
b7c81f37c0 | ||
|
|
5c3a7e4119 | ||
|
|
a94acef49b | ||
|
|
7f5b362eda | ||
|
|
ba5b3ad675 | ||
|
|
c1e4d1e7a4 | ||
|
|
dd8744b74e | ||
|
|
b775ecca08 | ||
|
|
b8f211a013 | ||
|
|
51534b2fae | ||
|
|
710db2ba0a | ||
|
|
32ef0d4dc3 | ||
|
|
b3cd80ba6d | ||
|
|
3f053f899e | ||
|
|
22b4d1734c | ||
|
|
46a71e81a0 | ||
|
|
b4851187ba | ||
|
|
0252969f7e | ||
|
|
f86cec4844 | ||
|
|
cd2e36da92 | ||
|
|
1b13107181 | ||
|
|
6fbde21995 | ||
|
|
a6608513ac | ||
|
|
d43c225be3 | ||
|
|
1802d7658d | ||
|
|
275f5d713f | ||
|
|
e40cfeec58 | ||
|
|
275b4b8d36 | ||
|
|
77cef632c7 | ||
|
|
db2064de14 | ||
|
|
e251c7b1c8 | ||
|
|
2fe98775f9 | ||
|
|
187179d87b | ||
|
|
dd03f6e8af | ||
|
|
07b32241bd | ||
|
|
abfff96cd4 | ||
|
|
735bdd1c20 | ||
|
|
9cae075b6f | ||
|
|
2317518e5e | ||
|
|
477af413c6 | ||
|
|
93f0f5ccae | ||
|
|
79b92727cc | ||
|
|
8dfd04672f | ||
|
|
603761e4b7 | ||
|
|
467c09f491 | ||
|
|
a953b494cb | ||
|
|
dca9afa10b | ||
|
|
23d2d87c24 | ||
|
|
c6b2d640ae | ||
|
|
b4b8a1d15b | ||
|
|
130d485cac | ||
|
|
d5b92744ed | ||
|
|
a5c4e16405 | ||
|
|
216266d7bf | ||
|
|
bf1652a1be | ||
|
|
f93f3d6012 | ||
|
|
41806f86ba | ||
|
|
59df97944f | ||
|
|
468651534e | ||
|
|
6343ae8161 | ||
|
|
641bd5eb15 | ||
|
|
063d989225 | ||
|
|
b8ca7b1591 | ||
|
|
e222f49c9d | ||
|
|
297bc635e8 | ||
|
|
230c65594c | ||
|
|
509a21ff05 | ||
|
|
96066712bd | ||
|
|
d83aa1e898 | ||
|
|
f0a7bdb6d6 | ||
|
|
9c077c98cd | ||
|
|
6dc45642b7 | ||
|
|
5c1b9c83f7 | ||
|
|
92438737c9 | ||
|
|
489cdd1b24 | ||
|
|
3f7995a7ea | ||
|
|
f7ad93229d | ||
|
|
555b4bc8c7 | ||
|
|
75f41bcb90 | ||
|
|
97e1fbc198 | ||
|
|
ee6d16f1b1 | ||
|
|
22d2097132 | ||
|
|
c376de9b5e | ||
|
|
ab2ef1e1e4 | ||
|
|
18030fa61e | ||
|
|
064337b5d3 | ||
|
|
a6a6fc48c1 | ||
|
|
d72e9bb05b | ||
|
|
7a9fdb4acd | ||
|
|
a6d0464735 | ||
|
|
52f69cc7dc | ||
|
|
0beadde758 | ||
|
|
618abd63cf | ||
|
|
34b3ddf63b | ||
|
|
ca76cac314 | ||
|
|
3a16ad89bd | ||
|
|
fb9369f333 | ||
|
|
66897611d9 | ||
|
|
6888554e9d | ||
|
|
f28a971b96 | ||
|
|
18808d0a61 | ||
|
|
86369148ee | ||
|
|
f45ee2ab4d | ||
|
|
2b73fab913 | ||
|
|
e0d750ac64 | ||
|
|
bb57c6e7b7 | ||
|
|
f346a052c1 | ||
|
|
3933353b5f | ||
|
|
6c9c21c135 | ||
|
|
d02a721eed | ||
|
|
8ffb4ae127 | ||
|
|
96fbeb583b | ||
|
|
33b98a15d3 | ||
|
|
e523ebe3c1 | ||
|
|
e17c671b7c | ||
|
|
e7565e1a2a | ||
|
|
b73d6377fc | ||
|
|
31f5fffc45 | ||
|
|
64c518c2f2 | ||
|
|
1ed543b0e8 | ||
|
|
8b7cd2dd1a | ||
|
|
8520b5211a | ||
|
|
03661e2a71 | ||
|
|
20b82b3638 | ||
|
|
cb499ae502 | ||
|
|
02b73207f9 | ||
|
|
53b5cbc12a | ||
|
|
f4c6decd2d | ||
|
|
69f1497986 | ||
|
|
2b46f01fe3 | ||
|
|
dd4adb57cf | ||
|
|
452bce07e1 | ||
|
|
8d702d0b77 | ||
|
|
e1dc4b69f5 | ||
|
|
6cd3580263 | ||
|
|
d5383aecc9 | ||
|
|
71cbbab2c9 | ||
|
|
8518d8f456 | ||
|
|
adc0db04bc | ||
|
|
c61fc59003 | ||
|
|
40f9072250 | ||
|
|
ea30bb351e | ||
|
|
b93550f6c8 | ||
|
|
60bd053095 | ||
|
|
8165b76001 | ||
|
|
efc563f5ff | ||
|
|
e52acc994c | ||
|
|
646833d3ec | ||
|
|
fd72c27afe | ||
|
|
c13bcc25c6 | ||
|
|
21c9ff6c85 | ||
|
|
4d6b367654 | ||
|
|
e2fd22a78e | ||
|
|
0759bdde01 | ||
|
|
faa03e0e14 | ||
|
|
f70897a6d3 | ||
|
|
ba231d2c5f | ||
|
|
095cb759ed | ||
|
|
5cbcb76039 | ||
|
|
3388b42f20 | ||
|
|
e1d541b02e | ||
|
|
cb784615ee | ||
|
|
321c5e049b | ||
|
|
ed7cf218f8 | ||
|
|
74d8368525 | ||
|
|
dcbfa272f9 | ||
|
|
42dd600e0c | ||
|
|
9689df601f | ||
|
|
f6019583b7 | ||
|
|
2d50a3335d | ||
|
|
202bfa987d | ||
|
|
93f9c7cfbd | ||
|
|
8f6a0bbf09 | ||
|
|
1a47c148e5 | ||
|
|
2435ba1ea0 | ||
|
|
9ba57a923b | ||
|
|
90e2b6f26b | ||
|
|
05f9f454c3 | ||
|
|
b85f59798c | ||
|
|
e80345a05b | ||
|
|
0bdcc3d616 | ||
|
|
987f12740e | ||
|
|
1265016a55 | ||
|
|
48d1de3678 | ||
|
|
43f6db3252 | ||
|
|
5b917e7d10 | ||
|
|
0523868a88 | ||
|
|
26f176eb7e | ||
|
|
ad32b5ca8f | ||
|
|
dbf14179dc | ||
|
|
45b0a4ec27 | ||
|
|
1969ee02a5 | ||
|
|
266b205c75 | ||
|
|
7dd3bad8bd | ||
|
|
4b45be7cda | ||
|
|
497ffd86fa | ||
|
|
0bdcc4269f | ||
|
|
e583c99f94 | ||
|
|
e22e50c3fa | ||
|
|
e9c9a3e1ce | ||
|
|
fa7bb71f3f | ||
|
|
34a3ad82e0 | ||
|
|
2f5d74dbf4 | ||
|
|
4bf5ba594c | ||
|
|
6e2da27f45 | ||
|
|
6ee9465d43 | ||
|
|
391a6bf422 | ||
|
|
5001a0e37d | ||
|
|
fd8d16a7db | ||
|
|
f3ac9306f3 | ||
|
|
59740d0b56 | ||
|
|
fb05a6c26f | ||
|
|
7943b708d2 | ||
|
|
04e37d1eca | ||
|
|
91b98e8c6d | ||
|
|
70234e5b19 | ||
|
|
ceff85d892 | ||
|
|
9f914dd42e | ||
|
|
24f5d68fef | ||
|
|
735fc325b1 | ||
|
|
178b216e48 | ||
|
|
5d0481f7a2 | ||
|
|
711bc69750 | ||
|
|
7263c9490d | ||
|
|
0c88bc6ac7 | ||
|
|
fda8d0a2e2 | ||
|
|
14bdf7fae8 | ||
|
|
d4ff7ecbaa | ||
|
|
030aec7373 | ||
|
|
6a351de4f9 | ||
|
|
bbff1c9c3e | ||
|
|
bbb8144129 | ||
|
|
83f3e23297 | ||
|
|
4f880932ae | ||
|
|
62e8c2497c | ||
|
|
37f854be3e | ||
|
|
e0e82e1877 | ||
|
|
95d8665dbe | ||
|
|
8667de994e | ||
|
|
cee0e22ce7 | ||
|
|
dc8a2f54e5 | ||
|
|
b3bc5b2520 | ||
|
|
00e929afac | ||
|
|
8a3bf6a5d9 | ||
|
|
d5f361d386 | ||
|
|
7bb4a27b60 | ||
|
|
3bd36feede | ||
|
|
fc1f1ce37c | ||
|
|
ee327dc87d | ||
|
|
d644ca5563 | ||
|
|
b3b1e37192 | ||
|
|
38f39c8d32 | ||
|
|
a773b7929c | ||
|
|
7b73103133 | ||
|
|
b6803191cb | ||
|
|
2b038a34c9 | ||
|
|
8c2c3f8bee | ||
|
|
e710836276 | ||
|
|
6be3c9a48a | ||
|
|
c0747bf68d | ||
|
|
0346dd15d9 | ||
|
|
ff0aa8423d | ||
|
|
0f718e0d08 | ||
|
|
9534a9ad30 | ||
|
|
d091857cef | ||
|
|
72a9ca0aa5 | ||
|
|
ecaae42b80 | ||
|
|
84bf1ec6e7 | ||
|
|
0bf3d20e07 | ||
|
|
5486ac5b9f | ||
|
|
ac12b2e643 | ||
|
|
16c281a9b7 | ||
|
|
413e3eb62d | ||
|
|
f31f341a50 | ||
|
|
c2501258b6 | ||
|
|
de1e3e1d4f | ||
|
|
a3f64d4e95 | ||
|
|
afc9a31080 | ||
|
|
e5699e8ba9 | ||
|
|
8a7143b791 | ||
|
|
79d23909b5 | ||
|
|
24fe4740d3 | ||
|
|
1e1d3f4aa8 | ||
|
|
51bf875826 | ||
|
|
f9ce6c7c81 | ||
|
|
2e91c3d334 | ||
|
|
d1b762af04 | ||
|
|
e1e02839d1 | ||
|
|
50a812ea5e | ||
|
|
27a4adb9c6 | ||
|
|
3932d8f48f | ||
|
|
d978a8e0a2 | ||
|
|
fad49e08d7 | ||
|
|
0f67b16f29 | ||
|
|
97edd23910 | ||
|
|
400ab2cdab | ||
|
|
db20ecf985 | ||
|
|
e59f421e79 | ||
|
|
75b7de712a | ||
|
|
fa8192177d | ||
|
|
48ffef7955 | ||
|
|
055796e6b3 | ||
|
|
34433c4962 | ||
|
|
6d1076e1f6 | ||
|
|
bb4081e503 | ||
|
|
bef25ad5f6 | ||
|
|
f47652e72d | ||
|
|
7c4d7fb3dd | ||
|
|
cdfc7281d0 | ||
|
|
500e80784a | ||
|
|
c5803d9b4c | ||
|
|
ebac00fbde | ||
|
|
f198ce29b1 | ||
|
|
df47e0ed63 | ||
|
|
477470ff70 | ||
|
|
aefddf7f5e | ||
|
|
5ce27b16f1 | ||
|
|
8302d6833d | ||
|
|
649c2eb676 | ||
|
|
a0b5e32f98 | ||
|
|
e73671a6ff | ||
|
|
9503aca78d | ||
|
|
dfaa8e4529 | ||
|
|
cbc3579e9a | ||
|
|
dd2e3d35fd | ||
|
|
ca9dccfcd7 | ||
|
|
64b00fce7d | ||
|
|
177ab0229a | ||
|
|
68b5e34fed | ||
|
|
2eda839303 | ||
|
|
71a01d3002 | ||
|
|
995548002b | ||
|
|
38ad16887b | ||
|
|
c20e8f7613 | ||
|
|
5bd4606854 | ||
|
|
e7b198849d | ||
|
|
3ab0d74af2 | ||
|
|
7ed5a8e72f | ||
|
|
57daa0f7f0 | ||
|
|
2dd3f169db | ||
|
|
b97b618b4b | ||
|
|
bb12488200 | ||
|
|
706a97b013 | ||
|
|
1cdb9c733a | ||
|
|
ffc525af9e | ||
|
|
1576dc1d13 | ||
|
|
4fbb5fbb25 | ||
|
|
e9da21a02e | ||
|
|
6c4d7ad8cc | ||
|
|
f1c026c5ec | ||
|
|
3d61c06ea9 | ||
|
|
22c1ee1f55 | ||
|
|
971960a242 | ||
|
|
69f8973339 | ||
|
|
bf1d9b6d06 | ||
|
|
6a2368f83c | ||
|
|
d0960f7f7f | ||
|
|
e5ad697466 | ||
|
|
188eab5faf | ||
|
|
2b257e3d0d | ||
|
|
77c9746be5 | ||
|
|
28cae607a4 | ||
|
|
814281ed7d | ||
|
|
5b0c8dd9dd | ||
|
|
650d8c45ec | ||
|
|
383d8980d6 | ||
|
|
6ea706c646 | ||
|
|
1ed2af08b8 | ||
|
|
7563a5abe0 | ||
|
|
0a8b187f80 | ||
|
|
275aa853f5 | ||
|
|
3614d57f9f | ||
|
|
1367873949 | ||
|
|
d933183e0a | ||
|
|
7e11def527 | ||
|
|
f3e53a05a6 | ||
|
|
dd381a5c1c | ||
|
|
8eee449305 | ||
|
|
96e02af0da | ||
|
|
60fb1478c3 | ||
|
|
aa7d0679df | ||
|
|
8e3cc192a5 | ||
|
|
0f939995d1 | ||
|
|
2e1bc9b14e | ||
|
|
fd1ac6ab2d | ||
|
|
d224924dc8 | ||
|
|
00e5ddd6f0 | ||
|
|
c603ca0e7a | ||
|
|
d07ef01204 | ||
|
|
d8630b5029 | ||
|
|
3b397326f8 | ||
|
|
81cabd08a9 | ||
|
|
5663c7dec3 | ||
|
|
06673b2108 | ||
|
|
6b7498a4b1 | ||
|
|
7f4ef493b9 | ||
|
|
d9d0dee0d5 | ||
|
|
9605370f0b | ||
|
|
7d9fc682a0 | ||
|
|
c4c08f2552 | ||
|
|
400740fdba | ||
|
|
42bce7c0bf | ||
|
|
a2281489a6 | ||
|
|
9bf7b0bf96 | ||
|
|
1f82ba74aa | ||
|
|
1062ac6ade | ||
|
|
aa5304a4f3 | ||
|
|
3a57ba1142 | ||
|
|
c0e7293360 | ||
|
|
dc1839760c | ||
|
|
a4e4b0fc17 | ||
|
|
743e4deb36 | ||
|
|
1d75f8478c | ||
|
|
cc0428aa50 | ||
|
|
4be481275f | ||
|
|
28cfe36f43 | ||
|
|
e0df78c5f7 | ||
|
|
4d8b058b65 | ||
|
|
da25611758 | ||
|
|
27732c85af | ||
|
|
5ffc84eb59 | ||
|
|
0a6e540394 | ||
|
|
9f09c73ec1 | ||
|
|
4bbab876ae | ||
|
|
b2fafeff19 | ||
|
|
79510a83de | ||
|
|
dd0afdfeb0 | ||
|
|
b6997c4455 | ||
|
|
2920732435 | ||
|
|
b9cfcce284 | ||
|
|
70d997964b | ||
|
|
4ffe71e1df | ||
|
|
cc2339fbe2 | ||
|
|
8fb859c0c4 | ||
|
|
5ff472dae0 | ||
|
|
6be4a6ed00 | ||
|
|
094d46293e | ||
|
|
c8d945db56 | ||
|
|
f78f0079c1 | ||
|
|
98d6bdb48a | ||
|
|
0391aebaeb | ||
|
|
46520edd87 | ||
|
|
14daa99802 | ||
|
|
4f9f67a477 | ||
|
|
85f182067c | ||
|
|
66ab6874f8 | ||
|
|
906b901e3d | ||
|
|
65adff4bdd | ||
|
|
e60fc0dc30 | ||
|
|
ffd719962c | ||
|
|
1a1f0c0a7c | ||
|
|
3944592c09 | ||
|
|
a5f862a564 | ||
|
|
489f25940f | ||
|
|
6288909481 | ||
|
|
c95f134963 | ||
|
|
024c2883c0 | ||
|
|
d7b0ecad75 | ||
|
|
50947b81c0 | ||
|
|
e5a1b721f1 | ||
|
|
aeb1a88e7a | ||
|
|
c406675d6a | ||
|
|
1ec193991b |
@@ -4,6 +4,13 @@ executors:
|
|||||||
docker:
|
docker:
|
||||||
- image: filecoin/rust:latest
|
- image: filecoin/rust:latest
|
||||||
working_directory: /mnt/crate
|
working_directory: /mnt/crate
|
||||||
|
doxygen:
|
||||||
|
docker:
|
||||||
|
- image: hrektts/doxygen
|
||||||
|
python:
|
||||||
|
docker:
|
||||||
|
- image: 3.7.7-stretch
|
||||||
|
|
||||||
|
|
||||||
restore-workspace: &restore-workspace
|
restore-workspace: &restore-workspace
|
||||||
attach_workspace:
|
attach_workspace:
|
||||||
@@ -12,7 +19,7 @@ restore-workspace: &restore-workspace
|
|||||||
restore-cache: &restore-cache
|
restore-cache: &restore-cache
|
||||||
restore_cache:
|
restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- cargo-v1-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
|
- cargo-v3-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
|
||||||
- repo-source-{{ .Branch }}-{{ .Revision }}
|
- repo-source-{{ .Branch }}-{{ .Revision }}
|
||||||
|
|
||||||
commands:
|
commands:
|
||||||
@@ -23,20 +30,9 @@ commands:
|
|||||||
steps:
|
steps:
|
||||||
- *restore-workspace
|
- *restore-workspace
|
||||||
- *restore-cache
|
- *restore-cache
|
||||||
- setup_remote_docker:
|
|
||||||
docker_layer_caching: true
|
|
||||||
# TODO: move into image
|
|
||||||
- run:
|
|
||||||
name: Install Docker client
|
|
||||||
command: |
|
|
||||||
set -x
|
|
||||||
VER="18.09.2"
|
|
||||||
curl -L -o /tmp/docker-$VER.tgz https://download.docker.com/linux/static/stable/x86_64/docker-$VER.tgz
|
|
||||||
tar -xz -C /tmp -f /tmp/docker-$VER.tgz
|
|
||||||
mv /tmp/docker/* /usr/bin
|
|
||||||
- run:
|
- run:
|
||||||
name: Test (<< parameters.target >>)
|
name: Test (<< parameters.target >>)
|
||||||
command: TARGET=<< parameters.target >> ci/run.sh
|
command: TARGET=<< parameters.target >> ci_scripts/run-rust-test.sh
|
||||||
no_output_timeout: 15m
|
no_output_timeout: 15m
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
@@ -44,30 +40,24 @@ jobs:
|
|||||||
executor: default
|
executor: default
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- run:
|
|
||||||
name: Update submodules
|
|
||||||
command: git submodule update --init --recursive
|
|
||||||
- run:
|
|
||||||
name: Calculate dependencies
|
|
||||||
command: cargo generate-lockfile
|
|
||||||
- restore_cache:
|
- restore_cache:
|
||||||
keys:
|
keys:
|
||||||
- cargo-v1-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
|
- cargo-v3-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
|
||||||
- run: rustup install $(cat rust-toolchain)
|
- run: rustup install $(cat rust-toolchain)
|
||||||
- run: rustup default $(cat rust-toolchain)
|
- run: rustup default $(cat rust-toolchain)
|
||||||
- run: rustup component add --toolchain $(cat rust-toolchain) rustfmt
|
- run: rustup component add --toolchain $(cat rust-toolchain) rustfmt
|
||||||
- run: rustup component add --toolchain $(cat rust-toolchain) clippy-preview
|
- run: rustup component add --toolchain $(cat rust-toolchain) clippy-preview
|
||||||
- run: cargo update
|
|
||||||
- run: cargo fetch
|
- run: cargo fetch
|
||||||
- run: rustc +stable --version
|
- run: rustc +stable --version
|
||||||
- run: rustc +$(cat rust-toolchain) --version
|
- run: rustc +$(cat rust-toolchain) --version
|
||||||
- run: rm -rf .git
|
# make sure this git repo doesn't grow too big
|
||||||
|
- run: git gc
|
||||||
- persist_to_workspace:
|
- persist_to_workspace:
|
||||||
root: /mnt
|
root: /mnt
|
||||||
paths:
|
paths:
|
||||||
- crate
|
- crate
|
||||||
- save_cache:
|
- save_cache:
|
||||||
key: cargo-v1-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
|
key: cargo-v3-{{ checksum "rust-toolchain" }}-{{ checksum "Cargo.toml" }}-{{ checksum "Cargo.lock" }}-{{ arch }}
|
||||||
paths:
|
paths:
|
||||||
- "~/.cargo"
|
- "~/.cargo"
|
||||||
- "~/.rustup"
|
- "~/.rustup"
|
||||||
@@ -98,11 +88,10 @@ jobs:
|
|||||||
curl https://sh.rustup.rs -sSf | sh -s -- -y
|
curl https://sh.rustup.rs -sSf | sh -s -- -y
|
||||||
- run: rustup install $(cat rust-toolchain)
|
- run: rustup install $(cat rust-toolchain)
|
||||||
- run: rustup default $(cat rust-toolchain)
|
- run: rustup default $(cat rust-toolchain)
|
||||||
- run: cargo update
|
|
||||||
- run: cargo fetch
|
- run: cargo fetch
|
||||||
- run:
|
- run:
|
||||||
name: Test
|
name: Test
|
||||||
command: TARGET=x86_64-apple-darwin ci/run.sh
|
command: TARGET=x86_64-apple-darwin ci_scripts/run-rust-test.sh
|
||||||
|
|
||||||
test_x86_64-unknown-linux-gnu:
|
test_x86_64-unknown-linux-gnu:
|
||||||
executor: default
|
executor: default
|
||||||
@@ -123,27 +112,25 @@ jobs:
|
|||||||
target: "aarch64-linux-android"
|
target: "aarch64-linux-android"
|
||||||
|
|
||||||
|
|
||||||
build_test_docs_wheel:
|
build_doxygen:
|
||||||
machine: True
|
executor: doxygen
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
# - run: docker pull deltachat/doxygen
|
- run: bash ci_scripts/run-doxygen.sh
|
||||||
- run: docker pull deltachat/coredeps
|
- run: mkdir -p workspace/c-docs
|
||||||
- run:
|
- run: cp -av deltachat-ffi/{html,xml} workspace/c-docs/
|
||||||
name: build docs, run tests and build wheels
|
- persist_to_workspace:
|
||||||
command: ci_scripts/ci_run.sh
|
root: workspace
|
||||||
environment:
|
paths:
|
||||||
TESTS: 1
|
- c-docs
|
||||||
DOCS: 1
|
|
||||||
|
|
||||||
- run:
|
|
||||||
name: copying docs and wheels to workspace
|
|
||||||
command: |
|
|
||||||
mkdir -p workspace/python
|
|
||||||
# cp -av docs workspace/c-docs
|
|
||||||
cp -av python/.docker-tox/wheelhouse workspace/
|
|
||||||
cp -av python/doc/_build/ workspace/py-docs
|
|
||||||
|
|
||||||
|
remote_python_packaging:
|
||||||
|
machine: true
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
# the following commands on success produces
|
||||||
|
# workspace/{wheelhouse,py-docs} as artefact directories
|
||||||
|
- run: bash ci_scripts/remote_python_packaging.sh
|
||||||
- persist_to_workspace:
|
- persist_to_workspace:
|
||||||
root: workspace
|
root: workspace
|
||||||
paths:
|
paths:
|
||||||
@@ -151,15 +138,22 @@ jobs:
|
|||||||
- py-docs
|
- py-docs
|
||||||
- wheelhouse
|
- wheelhouse
|
||||||
|
|
||||||
|
remote_tests_python:
|
||||||
|
machine: true
|
||||||
|
steps:
|
||||||
|
- checkout
|
||||||
|
- run: ci_scripts/remote_tests_python.sh
|
||||||
|
|
||||||
upload_docs_wheels:
|
upload_docs_wheels:
|
||||||
machine: true
|
machine: true
|
||||||
steps:
|
steps:
|
||||||
- checkout
|
- checkout
|
||||||
- attach_workspace:
|
- attach_workspace:
|
||||||
at: workspace
|
at: workspace
|
||||||
|
- run: pyenv versions
|
||||||
- run: pyenv global 3.5.2
|
- run: pyenv global 3.5.2
|
||||||
- run: ls -laR workspace
|
- run: ls -laR workspace
|
||||||
- run: ci_scripts/ci_upload.sh workspace/py-docs workspace/wheelhouse
|
- run: ci_scripts/ci_upload.sh workspace/py-docs workspace/wheelhouse workspace/c-docs
|
||||||
|
|
||||||
clippy:
|
clippy:
|
||||||
executor: default
|
executor: default
|
||||||
@@ -168,7 +162,7 @@ jobs:
|
|||||||
- *restore-cache
|
- *restore-cache
|
||||||
- run:
|
- run:
|
||||||
name: Run cargo clippy
|
name: Run cargo clippy
|
||||||
command: cargo clippy --all
|
command: cargo clippy
|
||||||
|
|
||||||
|
|
||||||
workflows:
|
workflows:
|
||||||
@@ -176,23 +170,49 @@ workflows:
|
|||||||
|
|
||||||
test:
|
test:
|
||||||
jobs:
|
jobs:
|
||||||
- build_test_docs_wheel
|
# - cargo_fetch
|
||||||
|
|
||||||
|
- remote_tests_python:
|
||||||
|
filters:
|
||||||
|
tags:
|
||||||
|
only: /.*/
|
||||||
|
|
||||||
|
- remote_python_packaging:
|
||||||
|
requires:
|
||||||
|
- remote_tests_python
|
||||||
|
filters:
|
||||||
|
branches:
|
||||||
|
only: master
|
||||||
|
tags:
|
||||||
|
only: /.*/
|
||||||
|
|
||||||
- upload_docs_wheels:
|
- upload_docs_wheels:
|
||||||
requires:
|
requires:
|
||||||
- build_test_docs_wheel
|
- remote_python_packaging
|
||||||
- cargo_fetch
|
- build_doxygen
|
||||||
- rustfmt:
|
filters:
|
||||||
requires:
|
branches:
|
||||||
- cargo_fetch
|
only: master
|
||||||
|
tags:
|
||||||
|
only: /.*/
|
||||||
|
# - rustfmt:
|
||||||
|
# requires:
|
||||||
|
# - cargo_fetch
|
||||||
|
# - clippy:
|
||||||
|
# requires:
|
||||||
|
# - cargo_fetch
|
||||||
|
|
||||||
- clippy:
|
- build_doxygen:
|
||||||
requires:
|
filters:
|
||||||
- cargo_fetch
|
branches:
|
||||||
|
only: master
|
||||||
|
tags:
|
||||||
|
only: /.*/
|
||||||
|
|
||||||
# Linux Desktop 64bit
|
# Linux Desktop 64bit
|
||||||
- test_x86_64-unknown-linux-gnu:
|
# - test_x86_64-unknown-linux-gnu:
|
||||||
requires:
|
# requires:
|
||||||
- cargo_fetch
|
# - cargo_fetch
|
||||||
|
|
||||||
# Linux Desktop 32bit
|
# Linux Desktop 32bit
|
||||||
# - test_i686-unknown-linux-gnu:
|
# - test_i686-unknown-linux-gnu:
|
||||||
|
|||||||
4
.gitattributes
vendored
@@ -2,6 +2,10 @@
|
|||||||
# ensures this even if the user has not set core.autocrlf.
|
# ensures this even if the user has not set core.autocrlf.
|
||||||
* text=auto
|
* text=auto
|
||||||
|
|
||||||
|
# This directory contains email messages verbatim, and changing CRLF to
|
||||||
|
# LF will corrupt them.
|
||||||
|
test-data/* text=false
|
||||||
|
|
||||||
# binary files should be detected by git, however, to be sure, you can add them here explicitly
|
# binary files should be detected by git, however, to be sure, you can add them here explicitly
|
||||||
*.png binary
|
*.png binary
|
||||||
*.jpg binary
|
*.jpg binary
|
||||||
|
|||||||
89
.github/workflows/ci.yml
vendored
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
name: Rust CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
- staging
|
||||||
|
- trying
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
name: Rustfmt
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: 1.43.1
|
||||||
|
override: true
|
||||||
|
- run: rustup component add rustfmt
|
||||||
|
- uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: fmt
|
||||||
|
args: --all -- --check
|
||||||
|
|
||||||
|
run_clippy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: 1.43.1
|
||||||
|
components: clippy
|
||||||
|
override: true
|
||||||
|
- uses: actions-rs/clippy-check@v1
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
|
|
||||||
|
build_and_test:
|
||||||
|
name: Build and test
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||||
|
rust: [nightly, 1.43.1]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
|
||||||
|
- name: Install ${{ matrix.rust }}
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: ${{ matrix.rust }}
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: Cache cargo registry
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/.cargo/registry
|
||||||
|
key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-registry-${{ hashFiles('**/Cargo.toml') }}
|
||||||
|
|
||||||
|
- name: Cache cargo index
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: ~/.cargo/git
|
||||||
|
key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-index-${{ hashFiles('**/Cargo.toml') }}
|
||||||
|
|
||||||
|
- name: Cache cargo build
|
||||||
|
uses: actions/cache@v2
|
||||||
|
with:
|
||||||
|
path: target
|
||||||
|
key: ${{ matrix.os }}-${{ matrix.rust }}-cargo-build-target-${{ hashFiles('**/Cargo.toml') }}
|
||||||
|
|
||||||
|
- name: check
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: check
|
||||||
|
args: --workspace --all --bins --examples --tests
|
||||||
|
|
||||||
|
- name: tests
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --workspace
|
||||||
|
|
||||||
3
.gitignore
vendored
@@ -16,9 +16,12 @@ python/.tox
|
|||||||
*.egg-info
|
*.egg-info
|
||||||
__pycache__
|
__pycache__
|
||||||
python/src/deltachat/capi*.so
|
python/src/deltachat/capi*.so
|
||||||
|
python/.venv/
|
||||||
|
|
||||||
python/liveconfig*
|
python/liveconfig*
|
||||||
|
|
||||||
# ignore doxgen generated files
|
# ignore doxgen generated files
|
||||||
deltachat-ffi/html
|
deltachat-ffi/html
|
||||||
deltachat-ffi/xml
|
deltachat-ffi/xml
|
||||||
|
|
||||||
|
.rsynclist
|
||||||
|
|||||||
54
ASYNC-API-TODO.txt
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
|
||||||
|
Delta Chat ASYNC (friedel, bjoern, floris, friedel)
|
||||||
|
|
||||||
|
- smtp fake-idle/load jobs gerade noch alle fuenf sekunden , sollte alle zehn minuten (oder gar nicht)
|
||||||
|
|
||||||
|
APIs:
|
||||||
|
dc_context_new # opens the database
|
||||||
|
dc_open # FFI only
|
||||||
|
-> drop it and move parameters to dc_context_new()
|
||||||
|
|
||||||
|
dc_configure # note: dc_start_jobs() is NOT allowed to run concurrently
|
||||||
|
dc_imex NEVER goes through the job system
|
||||||
|
dc_imex import_backup needs to ensure dc_stop_jobs()
|
||||||
|
|
||||||
|
dc_start_io # start smtp/imap and job handling subsystems
|
||||||
|
dc_stop_io # stop smtp/imap and job handling subsystems
|
||||||
|
dc_is_io_running # return 1 if smtp/imap/jobs susbystem is running
|
||||||
|
|
||||||
|
dc_close # FFI only
|
||||||
|
-> can be dropped
|
||||||
|
dc_context_unref
|
||||||
|
|
||||||
|
for ios share-extension:
|
||||||
|
Int dc_direct_send() -> try send out without going through jobs system, but queue a job in db if it needs to be retried on failure
|
||||||
|
0: message was sent
|
||||||
|
1: message failed to go out, is queued as a job to be retried later
|
||||||
|
2: message permanently failed?
|
||||||
|
|
||||||
|
EVENT handling:
|
||||||
|
start a callback thread and call get_next_event() which is BLOCKING
|
||||||
|
it's fine to start this callback thread later, it will see all events.
|
||||||
|
Note that the core infinitely fills the internal queue if you never drain it.
|
||||||
|
|
||||||
|
FFI-get_next_event() returns NULL if the context is unrefed already?
|
||||||
|
|
||||||
|
sidenote: how python's callback thread does it currently:
|
||||||
|
CB-thread runs this while loop:
|
||||||
|
while not QUITFLAG:
|
||||||
|
ev = context.get_next_event( )
|
||||||
|
...
|
||||||
|
So in order to shutdown properly one has to set QUITFLAG
|
||||||
|
before calling dc_stop_jobs() and dc_context_unref
|
||||||
|
|
||||||
|
event API:
|
||||||
|
get_data1_int
|
||||||
|
get_data2_int
|
||||||
|
get_data3_str
|
||||||
|
|
||||||
|
|
||||||
|
- userdata likely only used for the callbacks, likely can be dropped, needs verification
|
||||||
|
|
||||||
|
|
||||||
|
- iOS needs for the share app to call "try_send_smtp" wihtout a full dc_context_run and without going
|
||||||
|
|
||||||
586
CHANGELOG.md
Normal file
@@ -0,0 +1,586 @@
|
|||||||
|
# Changelog
|
||||||
|
|
||||||
|
## 1.39.0
|
||||||
|
|
||||||
|
- fix handling of `mvbox_watch`, `sentbox_watch`, `inbox_watch` #1654 #1658
|
||||||
|
|
||||||
|
- fix potential panics, update dependencies #1650 #1655
|
||||||
|
|
||||||
|
|
||||||
|
## 1.38.0
|
||||||
|
|
||||||
|
- fix sorting, esp. for multi-device
|
||||||
|
|
||||||
|
|
||||||
|
## 1.37.0
|
||||||
|
|
||||||
|
- improve ndn heuristics #1630
|
||||||
|
|
||||||
|
- get oauth2 authorizer from provider-db #1641
|
||||||
|
|
||||||
|
- removed linebreaks and spaces from generated qr-code #1631
|
||||||
|
|
||||||
|
- more fixes #1633 #1635 #1636 #1637
|
||||||
|
|
||||||
|
|
||||||
|
## 1.36.0
|
||||||
|
|
||||||
|
- parse ndn (network delivery notification) reports
|
||||||
|
and report failed messages as such #1552 #1622 #1630
|
||||||
|
|
||||||
|
- add oauth2 support for gsuite domains #1626
|
||||||
|
|
||||||
|
- read image orientation from exif before recoding #1619
|
||||||
|
|
||||||
|
- improve logging #1593 #1598
|
||||||
|
|
||||||
|
- improve python and bot bindings #1583 #1609
|
||||||
|
|
||||||
|
- improve imap logout #1595
|
||||||
|
|
||||||
|
- fix sorting #1600 #1604
|
||||||
|
|
||||||
|
- fix qr code generation #1631
|
||||||
|
|
||||||
|
- update rustcrypto releases #1603
|
||||||
|
|
||||||
|
- refactorings #1617
|
||||||
|
|
||||||
|
|
||||||
|
## 1.35.0
|
||||||
|
|
||||||
|
- enable strict-tls from a new provider-db setting #1587
|
||||||
|
|
||||||
|
- new subject 'Message from USER' for one-to-one chats #1395
|
||||||
|
|
||||||
|
- recode images #1563
|
||||||
|
|
||||||
|
- improve reconnect handling #1549 #1580
|
||||||
|
|
||||||
|
- improve importing addresses #1544
|
||||||
|
|
||||||
|
- improve configure and folder detection #1539 #1548
|
||||||
|
|
||||||
|
- improve test suite #1559 #1564 #1580 #1581 #1582 #1584 #1588:
|
||||||
|
|
||||||
|
- fix ad-hoc groups #1566
|
||||||
|
|
||||||
|
- preventions against being marked as spam #1575
|
||||||
|
|
||||||
|
- refactorings #1542 #1569
|
||||||
|
|
||||||
|
|
||||||
|
## 1.34.0
|
||||||
|
|
||||||
|
- new api for io, thread and event handling #1356,
|
||||||
|
see the example atop of `deltachat.h` to get an overview
|
||||||
|
|
||||||
|
- LOTS of speed improvements due to async processing #1356
|
||||||
|
|
||||||
|
- enable WAL mode for sqlite #1492
|
||||||
|
|
||||||
|
- process incoming messages in bulk #1527
|
||||||
|
|
||||||
|
- improve finding out the sent-folder #1488
|
||||||
|
|
||||||
|
- several bug fixes
|
||||||
|
|
||||||
|
|
||||||
|
## 1.33.0
|
||||||
|
|
||||||
|
- let `dc_set_muted()` also mute one-to-one chats #1470
|
||||||
|
|
||||||
|
- fix a bug that led to load and traffic if the server does not use sent-folder
|
||||||
|
#1472
|
||||||
|
|
||||||
|
|
||||||
|
## 1.32.0
|
||||||
|
|
||||||
|
- fix endless loop when trying to download messages with bad RFC Message-ID,
|
||||||
|
also be more reliable on similar errors #1463 #1466 #1462
|
||||||
|
|
||||||
|
- fix bug with comma in contact request #1438
|
||||||
|
|
||||||
|
- do not refer to hidden messages on replies #1459
|
||||||
|
|
||||||
|
- improve error handling #1468 #1465 #1464
|
||||||
|
|
||||||
|
|
||||||
|
## 1.31.0
|
||||||
|
|
||||||
|
- always describe the context of the displayed error #1451
|
||||||
|
|
||||||
|
- do not emit `DC_EVENT_ERROR` when message sending fails;
|
||||||
|
`dc_msg_get_state()` and `dc_get_msg_info()` are sufficient #1451
|
||||||
|
|
||||||
|
- new config-option `media_quality` #1449
|
||||||
|
|
||||||
|
- try over if writing message to database fails #1447
|
||||||
|
|
||||||
|
|
||||||
|
## 1.30.0
|
||||||
|
|
||||||
|
- expunge deleted messages #1440
|
||||||
|
|
||||||
|
- do not send `DC_EVENT_MSGS_CHANGED|INCOMING_MSG` on hidden messages #1439
|
||||||
|
|
||||||
|
|
||||||
|
## 1.29.0
|
||||||
|
|
||||||
|
- new config options `delete_device_after` and `delete_server_after`,
|
||||||
|
each taking an amount of seconds after which messages
|
||||||
|
are deleted from the device and/or the server #1310 #1335 #1411 #1417 #1423
|
||||||
|
|
||||||
|
- new api `dc_estimate_deletion_cnt()` to estimate the effect
|
||||||
|
of `delete_device_after` and `delete_server_after`
|
||||||
|
|
||||||
|
- use Ed25519 keys by default, these keys are much shorter
|
||||||
|
than RSA keys, which results in saving traffic and speed improvements #1362
|
||||||
|
|
||||||
|
- improve message ellipsizing #1397 #1430
|
||||||
|
|
||||||
|
- emit `DC_EVENT_ERROR_NETWORK` also on smtp-errors #1378
|
||||||
|
|
||||||
|
- do not show badly formatted non-delta-messages as empty #1384
|
||||||
|
|
||||||
|
- try over SMTP on potentially recoverable error 5.5.0 #1379
|
||||||
|
|
||||||
|
- remove device-chat from forward-to-chat-list #1367
|
||||||
|
|
||||||
|
- improve group-handling #1368
|
||||||
|
|
||||||
|
- `dc_get_info()` returns uptime (how long the context is in use)
|
||||||
|
|
||||||
|
- python improvements and adaptions #1408 #1415
|
||||||
|
|
||||||
|
- log to the stdout and stderr in tests #1416
|
||||||
|
|
||||||
|
- refactoring, code improvements #1363 #1365 #1366 #1370 #1375 #1389 #1390 #1418 #1419
|
||||||
|
|
||||||
|
- removed api: `dc_chat_get_subtitle()`, `dc_get_version_str()`, `dc_array_add_id()`
|
||||||
|
|
||||||
|
- removed events: `DC_EVENT_MEMBER_ADDED`, `DC_EVENT_MEMBER_REMOVED`
|
||||||
|
|
||||||
|
|
||||||
|
## 1.28.0
|
||||||
|
|
||||||
|
- new flag DC_GCL_FOR_FORWARDING for dc_get_chatlist()
|
||||||
|
that will sort the "saved messages" chat to the top of the chatlist #1336
|
||||||
|
- mark mails as being deleted from server in dc_empty_server() #1333
|
||||||
|
- fix interaction with servers that do not allow folder creation on root-level;
|
||||||
|
use path separator as defined by the email server #1359
|
||||||
|
- fix group creation if group was created by non-delta clients #1357
|
||||||
|
- fix showing replies from non-delta clients #1353
|
||||||
|
- fix member list on rejoining left groups #1343
|
||||||
|
- fix crash when using empty groups #1354
|
||||||
|
- fix potential crash on special names #1350
|
||||||
|
|
||||||
|
|
||||||
|
## 1.27.0
|
||||||
|
|
||||||
|
- handle keys reliably on armv7 #1327
|
||||||
|
|
||||||
|
|
||||||
|
## 1.26.0
|
||||||
|
|
||||||
|
- change generated key type back to RSA as shipped versions
|
||||||
|
have problems to encrypt to Ed25519 keys
|
||||||
|
|
||||||
|
- update rPGP to encrypt reliably to Ed25519 keys;
|
||||||
|
one of the next versions can finally use Ed25519 keys then
|
||||||
|
|
||||||
|
|
||||||
|
## 1.25.0
|
||||||
|
|
||||||
|
- save traffic by downloading only messages that are really displayed #1236
|
||||||
|
|
||||||
|
- change generated key type to Ed25519, these keys are much shorter
|
||||||
|
than RSA keys, which results in saving traffic and speed improvements #1287
|
||||||
|
|
||||||
|
- improve key handling #1237 #1240 #1242 #1247
|
||||||
|
|
||||||
|
- mute handling, apis are dc_set_chat_mute_duration()
|
||||||
|
dc_chat_is_muted() and dc_chat_get_remaining_mute_duration() #1143
|
||||||
|
|
||||||
|
- pinning chats, new apis are dc_set_chat_visibility() and
|
||||||
|
dc_chat_get_visibility() #1248
|
||||||
|
|
||||||
|
- add dc_provider_new_from_email() api that queries the new, integrated
|
||||||
|
provider-database #1207
|
||||||
|
|
||||||
|
- account creation by scanning a qr code
|
||||||
|
in the DCACCOUNT scheme (https://mailadm.readthedocs.io),
|
||||||
|
new api is dc_set_config_from_qr() #1249
|
||||||
|
|
||||||
|
- if possible, dc_join_securejoin(), returns the new chat-id immediately
|
||||||
|
and does the handshake in background #1225
|
||||||
|
|
||||||
|
- update imap and smtp dependencies #1115
|
||||||
|
|
||||||
|
- check for MOVE capability before using MOVE command #1263
|
||||||
|
|
||||||
|
- allow inline attachments from RFC 2183 #1280
|
||||||
|
|
||||||
|
- fix updating names from incoming mails #1298
|
||||||
|
|
||||||
|
- fix error messages shown on import #1234
|
||||||
|
|
||||||
|
- directly attempt to re-connect if the smtp connection is maybe stale #1296
|
||||||
|
|
||||||
|
- improve adding group members #1291
|
||||||
|
|
||||||
|
- improve rust-api #1261
|
||||||
|
|
||||||
|
- cleanup #1302 #1283 #1282 #1276 #1270-#1274 #1267 #1258-#1260
|
||||||
|
#1257 #1239 #1231 #1224
|
||||||
|
|
||||||
|
- update spec #1286 #1291
|
||||||
|
|
||||||
|
|
||||||
|
## 1.0.0-beta.24
|
||||||
|
|
||||||
|
- fix oauth2/gmail bug introduced in beta23 (not used in releases) #1219
|
||||||
|
|
||||||
|
- fix panic when receiving eg. cyrillic filenames #1216
|
||||||
|
|
||||||
|
- delete all consumed secure-join handshake messagess #1209 #1212
|
||||||
|
|
||||||
|
- rust-level cleanups #1218 #1217 #1210 #1205
|
||||||
|
|
||||||
|
- python-level cleanups #1204 #1202 #1201
|
||||||
|
|
||||||
|
|
||||||
|
## 1.0.0-beta.23
|
||||||
|
|
||||||
|
- #1197 fix imap-deletion of messages
|
||||||
|
|
||||||
|
- #1171 Combine multiple MDNs into a single mail, reducing traffic
|
||||||
|
|
||||||
|
- #1155 fix to not send out gossip always, reducing traffic
|
||||||
|
|
||||||
|
- #1160 fix reply-to-encrypted determination
|
||||||
|
|
||||||
|
- #1182 Add "Auto-Submitted: auto-replied" header to MDNs
|
||||||
|
|
||||||
|
- #1194 produce python wheels again, fix c/py.delta.chat
|
||||||
|
master-deployment
|
||||||
|
|
||||||
|
- rust-level housekeeping and improvements #1161 #1186 #1185 #1190 #1194 #1199 #1191 #1190 #1184 and more
|
||||||
|
|
||||||
|
- #1063 clarify licensing
|
||||||
|
|
||||||
|
- #1147 use mailparse 0.10.2
|
||||||
|
|
||||||
|
|
||||||
|
## 1.0.0-beta.22
|
||||||
|
|
||||||
|
- #1095 normalize email lineends to CRLF
|
||||||
|
|
||||||
|
- #1095 enable link-time-optimization, saves eg. on android 11 mb
|
||||||
|
|
||||||
|
- #1099 fix import regarding devicechats
|
||||||
|
|
||||||
|
- #1092 improve logging
|
||||||
|
|
||||||
|
- #1096 #1097 #1094 #1090 #1091 internal cleanups
|
||||||
|
|
||||||
|
## 1.0.0-beta.21
|
||||||
|
|
||||||
|
- #1078 #1082 ensure RFC compliance by producing 78 column lines for
|
||||||
|
encoded attachments.
|
||||||
|
|
||||||
|
- #1080 don't recreate and thus break group membership if an unknown
|
||||||
|
sender (or mailer-daemon) sends a message referencing the group chat
|
||||||
|
|
||||||
|
- #1081 #1079 some internal cleanups
|
||||||
|
|
||||||
|
- update imap-proto dependency, to fix yandex/oauth
|
||||||
|
|
||||||
|
## 1.0.0-beta.20
|
||||||
|
|
||||||
|
- #1074 fix OAUTH2/gmail
|
||||||
|
- #1072 fix group members not appearing in contact list
|
||||||
|
- #1071 never block interrupt_idle (thus hopefully also not on maybe_network())
|
||||||
|
- #1069 reduce smtp-timeout to 30 seconds
|
||||||
|
- #1066 #1065 avoid unwrap in dehtml, make literals more readable
|
||||||
|
|
||||||
|
## 1.0.0-beta.19
|
||||||
|
|
||||||
|
- #1058 timeout smtp-send if it doesn't complete in 15 minutes
|
||||||
|
|
||||||
|
- #1059 trim down logging
|
||||||
|
|
||||||
|
## 1.0.0-beta.18
|
||||||
|
|
||||||
|
- #1056 avoid panicking when we couldn't read imap-server's greeting
|
||||||
|
message
|
||||||
|
|
||||||
|
- #1055 avoid panicking when we don't have a selected folder
|
||||||
|
|
||||||
|
- #1052 #1049 #1051 improve logging to add thread-id/name and
|
||||||
|
file/lineno to each info/warn message.
|
||||||
|
|
||||||
|
- #1050 allow python bindings to initialize Account with "os_name".
|
||||||
|
|
||||||
|
|
||||||
|
## 1.0.0-beta.17
|
||||||
|
|
||||||
|
- #1044 implement avatar recoding to 192x192 in core to keep file sizes small.
|
||||||
|
|
||||||
|
- #1024 fix #1021 SQL/injection malformed Chat-Group-Name breakage
|
||||||
|
|
||||||
|
- #1036 fix smtp crash by pulling in a fixed async-smtp
|
||||||
|
|
||||||
|
- #1039 fix read-receipts appearing as normal messages when you change
|
||||||
|
MDN settings
|
||||||
|
|
||||||
|
- #1040 do not panic on SystemTimeDifference
|
||||||
|
|
||||||
|
- #1043 avoid potential crashes in malformed From/Chat-Disposition... headers
|
||||||
|
|
||||||
|
- #1045 #1041 #1038 #1035 #1034 #1029 #1025 various cleanups and doc
|
||||||
|
improvments
|
||||||
|
|
||||||
|
## 1.0.0-beta.16
|
||||||
|
|
||||||
|
- alleviate login problems with providers which only
|
||||||
|
support RSA1024 keys by switching back from Rustls
|
||||||
|
to native-tls, by using the new async-email/async-native-tls
|
||||||
|
crate from @dignifiedquire. thanks @link2xt.
|
||||||
|
|
||||||
|
- introduce per-contact profile images to send out
|
||||||
|
own profile image heuristically, and fix sending
|
||||||
|
out of profile images in "in-prepare" groups.
|
||||||
|
this also extends the Chat-spec that is maintained
|
||||||
|
in core to specify Chat-Group-Image and Chat-Group-Avatar
|
||||||
|
headers. thanks @r10s and @hpk42.
|
||||||
|
|
||||||
|
- fix merging of protected headers from the encrypted
|
||||||
|
to the unencrypted parts, now not happening recursively
|
||||||
|
anymore. thanks @hpk and @r10s
|
||||||
|
|
||||||
|
- fix/optimize autocrypt gossip headers to only get
|
||||||
|
sent when there are more than 2 people in a chat.
|
||||||
|
thanks @link2xt
|
||||||
|
|
||||||
|
- fix displayname to use the authenticated name
|
||||||
|
when available (displayname as coming from contacts
|
||||||
|
themselves). thanks @simon-laux
|
||||||
|
|
||||||
|
- introduce preliminary support for offline autoconfig
|
||||||
|
for nauta provider. thanks @hpk42 @r10s
|
||||||
|
|
||||||
|
## 1.0.0-beta.15
|
||||||
|
|
||||||
|
- fix #994 attachment appeared doubled in chats (and where actually
|
||||||
|
downloaded after smtp-send). @hpk42
|
||||||
|
|
||||||
|
## 1.0.0-beta.14
|
||||||
|
|
||||||
|
- fix packaging issue with our rust-email fork, now we are tracking
|
||||||
|
master again there. hpk42
|
||||||
|
|
||||||
|
## 1.0.0-beta.13
|
||||||
|
|
||||||
|
- fix #976 -- unicode-issues in display-name of email addresses. @hpk42
|
||||||
|
|
||||||
|
- fix #985 group add/remove member bugs resulting in broken groups. @hpk42
|
||||||
|
|
||||||
|
- fix hanging IMAP connections -- we now detect with a 15second timeout
|
||||||
|
if we cannot terminate the IDLE IMAP protocol. @hpk42 @link2xt
|
||||||
|
|
||||||
|
- fix incoming multipart/mixed containing html, to show up as
|
||||||
|
attachments again. Fixes usage for simplebot which sends html
|
||||||
|
files for users to interact with the bot. @adbenitez @hpk42
|
||||||
|
|
||||||
|
- refinements to internal autocrypt-handling code, do not send
|
||||||
|
prefer-encrypt=nopreference as it is the default if no attribute
|
||||||
|
is present. @linkxt
|
||||||
|
|
||||||
|
- simplify, modularize and rustify several parts
|
||||||
|
of dc-core (general WIP). @link2xt @flub @hpk42 @r10s
|
||||||
|
|
||||||
|
- use async-email/async-smtp to handle SMTP connections, might
|
||||||
|
fix connection/reconnection issues. @link2xt
|
||||||
|
|
||||||
|
- more tests and refinements for dealing with blobstorage @flub @hpk42
|
||||||
|
|
||||||
|
- use a dedicated build-server for CI testing of core PRs
|
||||||
|
|
||||||
|
|
||||||
|
## 1.0.0-beta.12
|
||||||
|
|
||||||
|
- fix python bindings to use core for copying attachments to blobdir
|
||||||
|
and fix core to actually do it. @hpk42
|
||||||
|
|
||||||
|
## 1.0.0-beta.11
|
||||||
|
|
||||||
|
- trigger reconnect more often on imap error states. Should fix an
|
||||||
|
issue observed when trying to empty a folder. @hpk42
|
||||||
|
|
||||||
|
- un-split qr tests: we fixed qr-securejoin protocol flakyness
|
||||||
|
last weeks. @hpk42
|
||||||
|
|
||||||
|
## 1.0.0-beta.10
|
||||||
|
|
||||||
|
- fix grpid-determination from in-reply-to and references headers. @hpk42
|
||||||
|
|
||||||
|
- only send Autocrypt-gossip headers on encrypted messages. @dignifiedquire
|
||||||
|
|
||||||
|
- fix reply-to-encrypted message to also be encrypted. @hpk42
|
||||||
|
|
||||||
|
- remove last unsafe code from dc_receive_imf :) @hpk42
|
||||||
|
|
||||||
|
- add experimental new dc_chat_get_info_json FFI/API so that desktop devs
|
||||||
|
can play with using it. @jikstra
|
||||||
|
|
||||||
|
- fix encoding of subjects and attachment-filenames @hpk42
|
||||||
|
@dignifiedquire .
|
||||||
|
|
||||||
|
## 1.0.0-beta.9
|
||||||
|
|
||||||
|
- historic: we now use the mailparse crate and lettre-email to generate mime
|
||||||
|
messages. This got rid of mmime completely, the C2rust generated port of the libetpan
|
||||||
|
mime-parse -- IOW 22KLocs of cumbersome code removed! see
|
||||||
|
https://github.com/deltachat/deltachat-core-rust/pull/904#issuecomment-561163330
|
||||||
|
many thanks @dignifiedquire for making everybody's life easier
|
||||||
|
and @jonhoo (from rust-imap fame) for suggesting to use the mailparse crate :)
|
||||||
|
|
||||||
|
- lots of improvements and better error handling in many rust modules
|
||||||
|
thanks @link2xt @flub @r10s, @hpk42 and @dignifiedquire
|
||||||
|
|
||||||
|
- @r10s introduced a new device chat which has an initial
|
||||||
|
welcome message. See
|
||||||
|
https://c.delta.chat/classdc__context__t.html#a1a2aad98bd23c1d21ee42374e241f389
|
||||||
|
for the main new FFI-API.
|
||||||
|
|
||||||
|
- fix moving self-sent messages, thanks @r10s, @flub, @hpk42
|
||||||
|
|
||||||
|
- fix flakyness/sometimes-failing verified/join-protocols,
|
||||||
|
thanks @flub, @r10s, @hpk42
|
||||||
|
|
||||||
|
- fix reply-to-encrypted message to keep encryption
|
||||||
|
|
||||||
|
- new DC_EVENT_SECUREJOIN_MEMBER_ADDED event
|
||||||
|
|
||||||
|
- many little fixes and rustifications (@link2xt, @flub, @hpk42)
|
||||||
|
|
||||||
|
|
||||||
|
## 1.0.0-beta.8
|
||||||
|
|
||||||
|
- now uses async-email/async-imap as the new base
|
||||||
|
which makes imap-idle interruptible and thus fixes
|
||||||
|
several issues around the imap thread being in zombie state .
|
||||||
|
thanks @dignifiedquire, @hpk42 and @link2xt.
|
||||||
|
|
||||||
|
- fixes imap-protocol parsing bugs that lead to infinitely
|
||||||
|
repeated crashing while trying to receive messages with
|
||||||
|
a subjec that contained non-utf8. thanks @link2xt
|
||||||
|
|
||||||
|
- fixed logic to find encryption subkey -- previously
|
||||||
|
delta chat would use the primary key for encryption
|
||||||
|
(which works with RSA but not ECC). thanks @link2xt
|
||||||
|
|
||||||
|
- introduce a new device chat where core and UIs can
|
||||||
|
add "device" messages. Android uses it for an initial
|
||||||
|
welcome message. thanks @r10s
|
||||||
|
|
||||||
|
- fix time smearing (when two message are virtually send
|
||||||
|
in the same second, there would be misbehaviour because
|
||||||
|
we didn't persist smeared time). thanks @r10s
|
||||||
|
|
||||||
|
- fix double-dotted extensions like .html.zip or .tar.gz
|
||||||
|
to not mangle them when creating blobfiles. thanks @flub
|
||||||
|
|
||||||
|
- fix backup/exports where the wrong sql file would be modified,
|
||||||
|
leading to problems when exporting twice. thanks @hpk42
|
||||||
|
|
||||||
|
- several other little fixes and improvements
|
||||||
|
|
||||||
|
|
||||||
|
## 1.0.0-beta.7
|
||||||
|
|
||||||
|
- fix location-streaming #782
|
||||||
|
|
||||||
|
- fix display of messages that could not be decrypted #785
|
||||||
|
|
||||||
|
- fix smtp MAILER-DAEMON bug #786
|
||||||
|
|
||||||
|
- fix a logging of durations #783
|
||||||
|
|
||||||
|
- add more error logging #779
|
||||||
|
|
||||||
|
- do not panic on some bad utf-8 mime #776
|
||||||
|
|
||||||
|
## 1.0.0-beta.6
|
||||||
|
|
||||||
|
- fix chatlist.get_msg_id to return id, instead of wrongly erroring
|
||||||
|
|
||||||
|
## 1.0.0-beta.5
|
||||||
|
|
||||||
|
- fix dc_get_msg() to return empty messages when asked for special ones
|
||||||
|
|
||||||
|
## 1.0.0-beta.4
|
||||||
|
|
||||||
|
- fix more than one sending of autocrypt setup message
|
||||||
|
|
||||||
|
- fix recognition of mailto-address-qr-codes, add tests
|
||||||
|
|
||||||
|
- tune down error to warning when adding self to chat
|
||||||
|
|
||||||
|
## 1.0.0-beta.3
|
||||||
|
|
||||||
|
- add back `dc_empty_server()` #682
|
||||||
|
|
||||||
|
- if `show_emails` is set to `DC_SHOW_EMAILS_ALL`,
|
||||||
|
email-based contact requests are added to the chatlist directly
|
||||||
|
|
||||||
|
- fix IMAP hangs #717 and cleanups
|
||||||
|
|
||||||
|
- several rPGP fixes
|
||||||
|
|
||||||
|
- code streamlining and rustifications
|
||||||
|
|
||||||
|
|
||||||
|
## 1.0.0-beta.2
|
||||||
|
|
||||||
|
- https://c.delta.chat docs are now regenerated again through our CI
|
||||||
|
|
||||||
|
- several rPGP cleanups, security fixes and better multi-platform support
|
||||||
|
|
||||||
|
- reconnect on io errors and broken pipes (imap)
|
||||||
|
|
||||||
|
- probe SMTP with real connection not just setup
|
||||||
|
|
||||||
|
- various imap/smtp related fixes
|
||||||
|
|
||||||
|
- use to_string_lossy in most places instead of relying on valid utf-8
|
||||||
|
encodings
|
||||||
|
|
||||||
|
- rework, rustify and test autoconfig-reading and parsing
|
||||||
|
|
||||||
|
- some rustifications/boolifications of c-ints
|
||||||
|
|
||||||
|
|
||||||
|
## 1.0.0-beta.1
|
||||||
|
|
||||||
|
- first beta of the Delta Chat Rust core library. many fixes of crashes
|
||||||
|
and other issues compared to 1.0.0-alpha.5.
|
||||||
|
|
||||||
|
- Most code is now "rustified" and does not do manual memory allocation anymore.
|
||||||
|
|
||||||
|
- The `DC_EVENT_GET_STRING` event is not used anymore, removing the last
|
||||||
|
event where the core requested a return value from the event callback.
|
||||||
|
|
||||||
|
Please now use `dc_set_stock_translation()` API for core messages
|
||||||
|
to be properly localized.
|
||||||
|
|
||||||
|
- Deltachat FFI docs are automatically generated and available here:
|
||||||
|
https://c.delta.chat
|
||||||
|
|
||||||
|
- New events ImapMessageMoved and ImapMessageDeleted
|
||||||
|
|
||||||
|
For a full list of changes, please see our closed Pull Requests:
|
||||||
|
|
||||||
|
https://github.com/deltachat/deltachat-core-rust/pulls?q=is%3Apr+is%3Aclosed
|
||||||
|
|
||||||
4100
Cargo.lock
generated
91
Cargo.toml
@@ -1,60 +1,78 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "deltachat"
|
name = "deltachat"
|
||||||
version = "1.0.0-alpha.4"
|
version = "1.39.0"
|
||||||
authors = ["dignifiedquire <dignifiedquire@gmail.com>"]
|
authors = ["Delta Chat Developers (ML) <delta@codespeak.net>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
license = "MPL"
|
license = "MPL-2.0"
|
||||||
|
|
||||||
[build-dependencies]
|
[profile.release]
|
||||||
cc = "1.0.35"
|
lto = true
|
||||||
pkg-config = "0.3"
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
deltachat_derive = { path = "./deltachat_derive" }
|
deltachat_derive = { path = "./deltachat_derive" }
|
||||||
|
|
||||||
libc = "0.2.51"
|
libc = "0.2.51"
|
||||||
pgp = { version = "0.2", default-features = false }
|
pgp = { version = "0.6.0", default-features = false }
|
||||||
hex = "0.3.2"
|
hex = "0.4.0"
|
||||||
sha2 = "0.8.0"
|
sha2 = "0.9.0"
|
||||||
rand = "0.6.5"
|
rand = "0.7.0"
|
||||||
phf = { git = "https://github.com/sfackler/rust-phf", rev = "0d00821", features = ["macros"] }
|
smallvec = "1.0.0"
|
||||||
smallvec = "0.6.9"
|
surf = { version = "2.0.0-alpha.4", default-features = false, features = ["h1-client"] }
|
||||||
reqwest = "0.9.15"
|
num-derive = "0.3.0"
|
||||||
num-derive = "0.2.5"
|
|
||||||
num-traits = "0.2.6"
|
num-traits = "0.2.6"
|
||||||
native-tls = "0.2.3"
|
async-smtp = { version = "0.3" }
|
||||||
lettre = "0.9.0"
|
email = { git = "https://github.com/deltachat/rust-email", branch = "master" }
|
||||||
imap = "1.0.1"
|
lettre_email = { git = "https://github.com/deltachat/lettre", branch = "master" }
|
||||||
mmime = "0.1.0"
|
async-imap = "0.3.1"
|
||||||
base64 = "0.10"
|
async-native-tls = { version = "0.3.3" }
|
||||||
|
async-std = { version = "1.6.1", features = ["unstable"] }
|
||||||
|
base64 = "0.12"
|
||||||
charset = "0.1"
|
charset = "0.1"
|
||||||
percent-encoding = "2.0"
|
percent-encoding = "2.0"
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
chrono = "0.4.6"
|
chrono = "0.4.6"
|
||||||
failure = "0.1.5"
|
indexmap = "1.3.0"
|
||||||
failure_derive = "0.1.5"
|
kamadak-exif = "0.5"
|
||||||
# TODO: make optional
|
lazy_static = "1.4.0"
|
||||||
rustyline = "4.1.0"
|
|
||||||
lazy_static = "1.3.0"
|
|
||||||
regex = "1.1.6"
|
regex = "1.1.6"
|
||||||
rusqlite = { version = "0.20", features = ["bundled"] }
|
strum = "0.18.0"
|
||||||
r2d2_sqlite = "0.12.0"
|
strum_macros = "0.18.0"
|
||||||
r2d2 = "0.8.5"
|
|
||||||
strum = "0.15.0"
|
|
||||||
strum_macros = "0.15.0"
|
|
||||||
thread-local-object = "0.1.0"
|
|
||||||
backtrace = "0.3.33"
|
backtrace = "0.3.33"
|
||||||
byteorder = "1.3.1"
|
byteorder = "1.3.1"
|
||||||
itertools = "0.8.0"
|
itertools = "0.8.0"
|
||||||
image-meta = "0.1.0"
|
image-meta = "0.1.0"
|
||||||
quick-xml = "0.15.0"
|
quick-xml = "0.18.1"
|
||||||
escaper = "0.1.0"
|
escaper = "0.1.0"
|
||||||
bitflags = "1.1.0"
|
bitflags = "1.1.0"
|
||||||
|
sanitize-filename = "0.2.1"
|
||||||
|
stop-token = { version = "0.1.1", features = ["unstable"] }
|
||||||
|
mailparse = "0.12.1"
|
||||||
|
encoded-words = { git = "https://github.com/async-email/encoded-words", branch="master" }
|
||||||
|
native-tls = "0.2.3"
|
||||||
|
image = { version = "0.23.5", default-features=false, features = ["gif", "jpeg", "ico", "png", "pnm", "webp", "bmp"] }
|
||||||
|
futures = "0.3.4"
|
||||||
|
thiserror = "1.0.14"
|
||||||
|
anyhow = "1.0.28"
|
||||||
|
async-trait = "0.1.31"
|
||||||
|
url = "2.1.1"
|
||||||
|
async-std-resolver = "0.19.5"
|
||||||
|
sqlx = { git = "https://github.com/launchbadge/sqlx", branch = "master", features = ["runtime-async-std", "sqlite", "macros"] }
|
||||||
|
libsqlite3-sys = { version = "0.18", features = ["bundled", "min_sqlite_version_3_7_16"] }
|
||||||
|
|
||||||
|
pretty_env_logger = { version = "0.4.0", optional = true }
|
||||||
|
log = { version = "0.4.8", optional = true }
|
||||||
|
rustyline = { version = "4.1.0", optional = true }
|
||||||
|
ansi_term = { version = "0.12.1", optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
tempfile = "3.0"
|
tempfile = "3.0"
|
||||||
pretty_assertions = "0.6.1"
|
pretty_assertions = "0.6.1"
|
||||||
pretty_env_logger = "0.3.0"
|
pretty_env_logger = "0.4.0"
|
||||||
|
proptest = "0.10"
|
||||||
|
async-std = { version = "1.6.0", features = ["unstable", "attributes"] }
|
||||||
|
smol = "0.1.11"
|
||||||
|
log = "0.4.8"
|
||||||
|
|
||||||
[workspace]
|
[workspace]
|
||||||
members = [
|
members = [
|
||||||
@@ -65,14 +83,17 @@ members = [
|
|||||||
[[example]]
|
[[example]]
|
||||||
name = "simple"
|
name = "simple"
|
||||||
path = "examples/simple.rs"
|
path = "examples/simple.rs"
|
||||||
|
required-features = ["repl"]
|
||||||
|
|
||||||
[[example]]
|
[[example]]
|
||||||
name = "repl"
|
name = "repl"
|
||||||
path = "examples/repl/main.rs"
|
path = "examples/repl/main.rs"
|
||||||
|
required-features = ["repl"]
|
||||||
|
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["nightly", "ringbuf"]
|
default = []
|
||||||
vendored = ["native-tls/vendored", "reqwest/default-tls-vendored"]
|
internals = []
|
||||||
|
repl = ["internals", "rustyline", "log", "pretty_env_logger", "ansi_term"]
|
||||||
|
vendored = ["async-native-tls/vendored", "async-smtp/native-tls-vendored"]
|
||||||
nightly = ["pgp/nightly"]
|
nightly = ["pgp/nightly"]
|
||||||
ringbuf = ["pgp/ringbuf"]
|
|
||||||
|
|||||||
3
LICENSE
@@ -2,9 +2,6 @@ The files in this directory and under its subdirectories
|
|||||||
are (c) 2019 by Bjoern Petersen and contributors and released under the
|
are (c) 2019 by Bjoern Petersen and contributors and released under the
|
||||||
Mozilla Public License Version 2.0, see below for a copy.
|
Mozilla Public License Version 2.0, see below for a copy.
|
||||||
|
|
||||||
NOTE that the files in the "libs" directory are copyrighted by third parties
|
|
||||||
and come with their own respective licenses.
|
|
||||||
|
|
||||||
Mozilla Public License Version 2.0
|
Mozilla Public License Version 2.0
|
||||||
==================================
|
==================================
|
||||||
|
|
||||||
|
|||||||
42
README.md
@@ -1,26 +1,25 @@
|
|||||||
# Delta Chat Rust
|
# Delta Chat Rust
|
||||||
|
|
||||||
> Project porting deltachat-core to rust
|
> Deltachat-core written in Rust
|
||||||
|
|
||||||
[![CircleCI build status][circle-shield]][circle] [![Appveyor build status][appveyor-shield]][appveyor]
|
[![CircleCI build status][circle-shield]][circle] [![Appveyor build status][appveyor-shield]][appveyor]
|
||||||
|
|
||||||
Current commit on deltachat/deltachat-core: `12ef73c8e76185f9b78e844ea673025f56a959ab`.
|
|
||||||
|
|
||||||
## Installing Rust and Cargo
|
## Installing Rust and Cargo
|
||||||
|
|
||||||
To download and install the official compiler for the Rust programming language, and the Cargo package manager, run the command in your user environment:
|
To download and install the official compiler for the Rust programming language, and the Cargo package manager, run the command in your user environment:
|
||||||
|
|
||||||
```
|
```
|
||||||
curl https://sh.rustup.rs -sSf | sh
|
$ curl https://sh.rustup.rs -sSf | sh
|
||||||
```
|
```
|
||||||
|
|
||||||
## Using the CLI client
|
## Using the CLI client
|
||||||
|
|
||||||
Compile and run Delta Chat Core using `cargo`:
|
Compile and run Delta Chat Core command line utility, using `cargo`:
|
||||||
|
|
||||||
```
|
```
|
||||||
cargo run --example repl -- /path/to/db
|
$ RUST_LOG=info cargo run --example repl --features repl -- ~/deltachat-db
|
||||||
```
|
```
|
||||||
|
where ~/deltachat-db is the database file. Delta Chat will create it if it does not exist.
|
||||||
|
|
||||||
Configure your account (if not already configured):
|
Configure your account (if not already configured):
|
||||||
|
|
||||||
@@ -89,6 +88,15 @@ $ cargo test --all
|
|||||||
$ cargo build -p deltachat_ffi --release
|
$ cargo build -p deltachat_ffi --release
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Debugging environment variables
|
||||||
|
|
||||||
|
- `DCC_IMAP_DEBUG`: if set IMAP protocol commands and responses will be
|
||||||
|
printed
|
||||||
|
|
||||||
|
- `DCC_MIME_DEBUG`: if set outgoing and incoming message will be printed
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
### Expensive tests
|
### Expensive tests
|
||||||
|
|
||||||
Some tests are expensive and marked with `#[ignore]`, to run these
|
Some tests are expensive and marked with `#[ignore]`, to run these
|
||||||
@@ -101,9 +109,29 @@ $ cargo test -- --ignored
|
|||||||
|
|
||||||
- `vendored`: When using Openssl for TLS, this bundles a vendored version.
|
- `vendored`: When using Openssl for TLS, this bundles a vendored version.
|
||||||
- `nightly`: Enable nightly only performance and security related features.
|
- `nightly`: Enable nightly only performance and security related features.
|
||||||
- `ringbuf`: Enable the use of [`slice_deque`](https://github.com/gnzlbg/slice_deque) in pgp.
|
|
||||||
|
|
||||||
[circle-shield]: https://img.shields.io/circleci/project/github/deltachat/deltachat-core-rust/master.svg?style=flat-square
|
[circle-shield]: https://img.shields.io/circleci/project/github/deltachat/deltachat-core-rust/master.svg?style=flat-square
|
||||||
[circle]: https://circleci.com/gh/deltachat/deltachat-core-rust/
|
[circle]: https://circleci.com/gh/deltachat/deltachat-core-rust/
|
||||||
[appveyor-shield]: https://ci.appveyor.com/api/projects/status/lqpegel3ld4ipxj8/branch/master?style=flat-square
|
[appveyor-shield]: https://ci.appveyor.com/api/projects/status/lqpegel3ld4ipxj8/branch/master?style=flat-square
|
||||||
[appveyor]: https://ci.appveyor.com/project/dignifiedquire/deltachat-core-rust/branch/master
|
[appveyor]: https://ci.appveyor.com/project/dignifiedquire/deltachat-core-rust/branch/master
|
||||||
|
|
||||||
|
## Language bindings and frontend projects
|
||||||
|
|
||||||
|
Language bindings are available for:
|
||||||
|
|
||||||
|
- [C](https://c.delta.chat)
|
||||||
|
- [Node.js](https://www.npmjs.com/package/deltachat-node)
|
||||||
|
- [Python](https://py.delta.chat)
|
||||||
|
- [Go](https://github.com/hugot/go-deltachat/)
|
||||||
|
- [Free Pascal](https://github.com/deltachat/deltachat-fp/)
|
||||||
|
- **Java** and **Swift** (contained in the Android/iOS repos)
|
||||||
|
|
||||||
|
The following "frontend" projects make use of the Rust-library
|
||||||
|
or its language bindings:
|
||||||
|
|
||||||
|
- [Android](https://github.com/deltachat/deltachat-android)
|
||||||
|
- [iOS](https://github.com/deltachat/deltachat-ios)
|
||||||
|
- [Desktop](https://github.com/deltachat/deltachat-desktop)
|
||||||
|
- [Pidgin](https://code.ur.gs/lupine/purple-plugin-delta/)
|
||||||
|
- [Telepathy](https://code.ur.gs/lupine/telepathy-padfoot/)
|
||||||
|
- several **Bots**
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
[dependencies.std]
|
|
||||||
features = ["panic-unwind"]
|
|
||||||
|
|
||||||
# if using `cargo test`
|
|
||||||
[dependencies.test]
|
|
||||||
stage = 1
|
|
||||||
20
appveyor.yml
@@ -1,20 +0,0 @@
|
|||||||
environment:
|
|
||||||
matrix:
|
|
||||||
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
|
||||||
|
|
||||||
install:
|
|
||||||
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
|
|
||||||
- rustup-init -yv --default-toolchain nightly-2019-07-10
|
|
||||||
- set PATH=%PATH%;%USERPROFILE%\.cargo\bin
|
|
||||||
- rustc -vV
|
|
||||||
- cargo -vV
|
|
||||||
- cargo update
|
|
||||||
|
|
||||||
build: false
|
|
||||||
|
|
||||||
test_script:
|
|
||||||
- cargo test --release
|
|
||||||
|
|
||||||
cache:
|
|
||||||
- target
|
|
||||||
- C:\Users\appveyor\.cargo\registry
|
|
||||||
BIN
assets/icon-device.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
83
assets/icon-device.svg
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
inkscape:export-ydpi="409.60001"
|
||||||
|
inkscape:export-xdpi="409.60001"
|
||||||
|
inkscape:export-filename="/Users/bpetersen/projects/deltachat-core-rust/assets/icon-device.png"
|
||||||
|
version="1.0"
|
||||||
|
width="60"
|
||||||
|
height="60"
|
||||||
|
viewBox="0 0 45 45"
|
||||||
|
preserveAspectRatio="xMidYMid meet"
|
||||||
|
id="svg4344"
|
||||||
|
sodipodi:docname="icon-device.svg"
|
||||||
|
inkscape:version="1.0beta1 (32d4812, 2019-09-19)">
|
||||||
|
<defs
|
||||||
|
id="defs4348" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
inkscape:snap-global="false"
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
inkscape:document-rotation="0"
|
||||||
|
borderopacity="1"
|
||||||
|
objecttolerance="10"
|
||||||
|
gridtolerance="10"
|
||||||
|
guidetolerance="10"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:window-width="1600"
|
||||||
|
inkscape:window-height="1035"
|
||||||
|
id="namedview4346"
|
||||||
|
showgrid="false"
|
||||||
|
units="px"
|
||||||
|
inkscape:zoom="3.959798"
|
||||||
|
inkscape:cx="28.322498"
|
||||||
|
inkscape:cy="24.898474"
|
||||||
|
inkscape:window-x="45"
|
||||||
|
inkscape:window-y="23"
|
||||||
|
inkscape:window-maximized="0"
|
||||||
|
inkscape:current-layer="svg4344" />
|
||||||
|
<metadata
|
||||||
|
id="metadata4336">
|
||||||
|
Created by potrace 1.15, written by Peter Selinger 2001-2017
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<rect
|
||||||
|
y="-4.4408921e-16"
|
||||||
|
x="0"
|
||||||
|
height="45"
|
||||||
|
width="45"
|
||||||
|
id="rect860"
|
||||||
|
style="opacity:1;fill:#76868b;fill-opacity:1;stroke-width:0.819271" />
|
||||||
|
<g
|
||||||
|
fill="#000000"
|
||||||
|
stroke="none"
|
||||||
|
style="fill:#ffffff;fill-opacity:1"
|
||||||
|
transform="matrix(0.00255113,0,0,-0.00255113,5.586152,38.200477)"
|
||||||
|
id="g4342">
|
||||||
|
<path
|
||||||
|
style="fill:#ffffff;fill-opacity:1"
|
||||||
|
d="m 8175,12765 c -703,-114 -1248,-608 -1387,-1258 -17,-82 -21,-136 -22,-277 0,-202 15,-307 70,-470 149,-446 499,-733 1009,-828 142,-26 465,-23 619,6 691,131 1201,609 1328,1244 31,158 31,417 0,565 -114,533 -482,889 -1038,1004 -133,27 -448,35 -579,14 z"
|
||||||
|
id="path4338"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
<path
|
||||||
|
style="fill:#ffffff;fill-opacity:1"
|
||||||
|
d="m 7070,9203 c -212,-20 -275,-27 -397,-48 -691,-117 -1400,-444 -2038,-940 -182,-142 -328,-270 -585,-517 -595,-571 -911,-974 -927,-1181 -6,-76 11,-120 69,-184 75,-80 159,-108 245,-79 109,37 263,181 632,595 539,606 774,826 1035,969 135,75 231,105 341,106 82,1 94,-2 138,-27 116,-68 161,-209 122,-376 -9,-36 -349,-868 -757,-1850 -407,-982 -785,-1892 -838,-2021 -287,-694 -513,-1389 -615,-1889 -70,-342 -90,-683 -52,-874 88,-440 381,-703 882,-792 124,-23 401,-30 562,-16 783,69 1674,461 2561,1125 796,596 1492,1354 1607,1751 43,146 -33,308 -168,360 -61,23 -100,15 -173,-36 -105,-74 -202,-170 -539,-529 -515,-551 -762,-783 -982,-927 -251,-164 -437,-186 -543,-65 -56,64 -74,131 -67,247 13,179 91,434 249,815 135,324 1588,4102 1646,4280 106,325 151,561 159,826 9,281 -22,463 -112,652 -58,122 -114,199 -211,292 -245,233 -582,343 -1044,338 -91,-1 -181,-3 -200,-5 z"
|
||||||
|
id="path4340"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 3.4 KiB |
BIN
assets/icon-saved-messages.png
Normal file
|
After Width: | Height: | Size: 3.9 KiB |
71
assets/icon-saved-messages.svg
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<svg
|
||||||
|
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||||
|
xmlns:cc="http://creativecommons.org/ns#"
|
||||||
|
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||||
|
xmlns:svg="http://www.w3.org/2000/svg"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||||
|
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||||
|
inkscape:export-ydpi="409.60001"
|
||||||
|
inkscape:export-xdpi="409.60001"
|
||||||
|
inkscape:export-filename="/home/kerle/test-icon.png"
|
||||||
|
version="1.0"
|
||||||
|
width="60"
|
||||||
|
height="60"
|
||||||
|
viewBox="0 0 45 45"
|
||||||
|
preserveAspectRatio="xMidYMid meet"
|
||||||
|
id="svg4344"
|
||||||
|
sodipodi:docname="icon-saved-messages.svg"
|
||||||
|
inkscape:version="1.0beta1 (32d4812, 2019-09-19)">
|
||||||
|
<defs
|
||||||
|
id="defs4348" />
|
||||||
|
<sodipodi:namedview
|
||||||
|
pagecolor="#ffffff"
|
||||||
|
bordercolor="#666666"
|
||||||
|
inkscape:document-rotation="0"
|
||||||
|
borderopacity="1"
|
||||||
|
objecttolerance="10"
|
||||||
|
gridtolerance="10"
|
||||||
|
guidetolerance="10"
|
||||||
|
inkscape:pageopacity="0"
|
||||||
|
inkscape:pageshadow="2"
|
||||||
|
inkscape:window-width="1395"
|
||||||
|
inkscape:window-height="855"
|
||||||
|
id="namedview4346"
|
||||||
|
showgrid="false"
|
||||||
|
units="px"
|
||||||
|
inkscape:zoom="4"
|
||||||
|
inkscape:cx="29.308676"
|
||||||
|
inkscape:cy="49.03624"
|
||||||
|
inkscape:window-x="89"
|
||||||
|
inkscape:window-y="108"
|
||||||
|
inkscape:window-maximized="0"
|
||||||
|
inkscape:current-layer="svg4344"
|
||||||
|
inkscape:lockguides="false" />
|
||||||
|
<metadata
|
||||||
|
id="metadata4336">
|
||||||
|
Created by potrace 1.15, written by Peter Selinger 2001-2017
|
||||||
|
<rdf:RDF>
|
||||||
|
<cc:Work
|
||||||
|
rdf:about="">
|
||||||
|
<dc:format>image/svg+xml</dc:format>
|
||||||
|
<dc:type
|
||||||
|
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||||
|
<dc:title />
|
||||||
|
</cc:Work>
|
||||||
|
</rdf:RDF>
|
||||||
|
</metadata>
|
||||||
|
<rect
|
||||||
|
y="0"
|
||||||
|
x="0"
|
||||||
|
height="45"
|
||||||
|
width="45"
|
||||||
|
id="rect1420"
|
||||||
|
style="fill:#87aade;fill-opacity:1;stroke:none;stroke-width:0.968078" />
|
||||||
|
<path
|
||||||
|
id="rect846"
|
||||||
|
style="fill:#ffffff;stroke-width:0.58409804"
|
||||||
|
d="M 13.5,7.5 V 39 h 0.08654 L 22.533801,29.370239 31.482419,39 h 0.01758 V 7.5 Z m 9.004056,4.108698 1.879508,4.876388 5.039514,0.359779 -3.879358,3.363728 1.227764,5.095749 -4.276893,-2.796643 -4.280949,2.788618 1.237229,-5.093073 -3.873949,-3.371754 5.040866,-0.350417 z"
|
||||||
|
inkscape:connector-curvature="0" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 2.3 KiB |
BIN
assets/welcome-image.jpg
Normal file
|
After Width: | Height: | Size: 113 KiB |
38
build.rs
@@ -1,38 +0,0 @@
|
|||||||
extern crate cc;
|
|
||||||
|
|
||||||
fn link_static(lib: &str) {
|
|
||||||
println!("cargo:rustc-link-lib=static={}", lib);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn link_framework(fw: &str) {
|
|
||||||
println!("cargo:rustc-link-lib=framework={}", fw);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_search_path(p: &str) {
|
|
||||||
println!("cargo:rustc-link-search={}", p);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn build_tools() {
|
|
||||||
let mut config = cc::Build::new();
|
|
||||||
config.file("misc.c").compile("libtools.a");
|
|
||||||
|
|
||||||
println!("rerun-if-changed=build.rs");
|
|
||||||
println!("rerun-if-changed=misc.h");
|
|
||||||
println!("rerun-if-changed=misc.c");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
build_tools();
|
|
||||||
|
|
||||||
add_search_path("/usr/local/lib");
|
|
||||||
|
|
||||||
let target = std::env::var("TARGET").unwrap();
|
|
||||||
if target.contains("-apple") || target.contains("-darwin") {
|
|
||||||
link_framework("CoreFoundation");
|
|
||||||
link_framework("CoreServices");
|
|
||||||
link_framework("Security");
|
|
||||||
}
|
|
||||||
|
|
||||||
// local tools
|
|
||||||
link_static("tools");
|
|
||||||
}
|
|
||||||
@@ -1,52 +1,46 @@
|
|||||||
|
|
||||||
# Continuous Integration Scripts for Delta Chat
|
# Continuous Integration Scripts for Delta Chat
|
||||||
|
|
||||||
Continuous Integration is run through CircleCI
|
Continuous Integration, run through CircleCI and an own build machine.
|
||||||
but is largely independent of it.
|
|
||||||
|
## Description of scripts
|
||||||
|
|
||||||
|
- `../.circleci/config.yml` describing the build jobs that are run
|
||||||
|
by Circle-CI
|
||||||
|
|
||||||
|
- `remote_tests_python.sh` rsyncs to a build machine and runs
|
||||||
|
`run-python-test.sh` remotely on the build machine.
|
||||||
|
|
||||||
|
- `remote_tests_rust.sh` rsyncs to the build machine and runs
|
||||||
|
`run-rust-test.sh` remotely on the build machine.
|
||||||
|
|
||||||
|
- `doxygen/Dockerfile` specifies an image that contains
|
||||||
|
the doxygen tool which is used by `run-doxygen.sh`
|
||||||
|
to generate C-docs which are then uploaded
|
||||||
|
via `ci_upload.sh` to `https://c.delta.chat/_unofficial_unreleased_docs/<BRANCH>`
|
||||||
|
(and the master branch is linked to https://c.delta.chat proper).
|
||||||
|
|
||||||
|
|
||||||
## Generating docker containers for performing build step work
|
## Triggering runs on the build machine locally (fast!)
|
||||||
|
|
||||||
All tests, docs and wheel building is run in docker containers:
|
There is experimental support for triggering a remote Python or Rust test run
|
||||||
|
from your local checkout/branch. You will need to be authorized to login to
|
||||||
|
the build machine (ask your friendly sysadmin on #deltachat freenode) to type::
|
||||||
|
|
||||||
- **coredeps/Dockerfile** specifies an image that contains all
|
ci_scripts/manual_remote_tests.sh rust
|
||||||
of Delta Chat's core dependencies as linkable libraries.
|
ci_scripts/manual_remote_tests.sh python
|
||||||
It also serves to run python tests and build wheels
|
|
||||||
(binary packages for Python).
|
|
||||||
|
|
||||||
- **doxygen/Dockerfile** specifies an image that contains
|
This will **rsync** your current checkout to the remote build machine
|
||||||
the doxygen tool which is used to generate C-docs.
|
(no need to commit before) and then run either rust or python tests.
|
||||||
|
|
||||||
To run tests locally you can pull existing images from "docker.io",
|
# Outdated files (for later re-use)
|
||||||
the hub for sharing Docker images::
|
|
||||||
|
|
||||||
docker pull deltachat/coredeps
|
`coredeps/Dockerfile` specifies an image that contains all
|
||||||
docker pull deltachat/doxygen
|
of Delta Chat's core dependencies. It used to run
|
||||||
|
python tests and build wheels (binary packages for Python)
|
||||||
|
|
||||||
or you can build the docker images yourself locally
|
You can build the docker images yourself locally
|
||||||
to avoid the relatively large download::
|
to avoid the relatively large download::
|
||||||
|
|
||||||
cd ci_scripts # where all CI things are
|
cd ci_scripts # where all CI things are
|
||||||
docker build -t deltachat/coredeps docker-coredeps
|
docker build -t deltachat/coredeps docker-coredeps
|
||||||
docker build -t deltachat/doxygen docker-doxygen
|
docker build -t deltachat/doxygen docker-doxygen
|
||||||
|
|
||||||
## ci_run.sh (main entrypoint called by circle-ci)
|
|
||||||
|
|
||||||
Once you have the docker images available
|
|
||||||
you can run python testing, documentation generation
|
|
||||||
and building binary wheels::
|
|
||||||
|
|
||||||
sh DOCS=1 TESTS=1 ci_scripts/ci_run.sh
|
|
||||||
|
|
||||||
## ci_upload.sh (uploading artifacts on success)
|
|
||||||
|
|
||||||
- python docs to `https://py.delta.chat/_unofficial_unreleased_docs/<BRANCH>`
|
|
||||||
|
|
||||||
- doxygen docs to `https://c.delta.chat/_unofficial_unreleased_docs/<BRANCH>`
|
|
||||||
|
|
||||||
- python wheels to `https://m.devpi.net/dc/<BRANCH>`
|
|
||||||
so that you install fully self-contained wheels like this:
|
|
||||||
`pip install -U -i https://m.devpi.net/dc/<BRANCH> deltachat`
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
# perform CI jobs on PRs and after merges to master.
|
|
||||||
# triggered from .circleci/config.yml
|
|
||||||
|
|
||||||
set -e -x
|
|
||||||
|
|
||||||
export BRANCH=${CIRCLE_BRANCH:-test7}
|
|
||||||
|
|
||||||
# run doxygen on c-source (needed by later doc-generation steps).
|
|
||||||
# XXX modifies the host filesystem docs/xml and docs/html directories
|
|
||||||
# XXX which you can then only remove with sudo as they belong to root
|
|
||||||
|
|
||||||
# XXX we don't do doxygen doc generation with Rust anymore, needs to be
|
|
||||||
# substituted with rust-docs
|
|
||||||
#if [ -n "$DOCS" ] ; then
|
|
||||||
# docker run --rm -it -v $PWD:/mnt -w /mnt/docs deltachat/doxygen doxygen
|
|
||||||
#fi
|
|
||||||
|
|
||||||
# run everything else inside docker (TESTS, DOCS, WHEELS)
|
|
||||||
docker run -e DCC_PY_LIVECONFIG -e BRANCH -e TESTS -e DOCS \
|
|
||||||
--rm -it -v $(pwd):/mnt -w /mnt \
|
|
||||||
deltachat/coredeps ci_scripts/run_all.sh
|
|
||||||
|
|
||||||
@@ -7,9 +7,9 @@ fi
|
|||||||
|
|
||||||
set -xe
|
set -xe
|
||||||
|
|
||||||
#DOXYDOCDIR=${1:?directory where doxygen docs to be found}
|
|
||||||
PYDOCDIR=${1:?directory with python docs}
|
PYDOCDIR=${1:?directory with python docs}
|
||||||
WHEELHOUSEDIR=${2:?directory with pre-built wheels}
|
WHEELHOUSEDIR=${2:?directory with pre-built wheels}
|
||||||
|
DOXYDOCDIR=${3:?directory where doxygen docs to be found}
|
||||||
|
|
||||||
export BRANCH=${CIRCLE_BRANCH:?specify branch for uploading purposes}
|
export BRANCH=${CIRCLE_BRANCH:?specify branch for uploading purposes}
|
||||||
|
|
||||||
@@ -17,15 +17,18 @@ export BRANCH=${CIRCLE_BRANCH:?specify branch for uploading purposes}
|
|||||||
# python docs to py.delta.chat
|
# python docs to py.delta.chat
|
||||||
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null delta@py.delta.chat mkdir -p build/${BRANCH}
|
ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null delta@py.delta.chat mkdir -p build/${BRANCH}
|
||||||
rsync -avz \
|
rsync -avz \
|
||||||
|
--delete \
|
||||||
-e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" \
|
-e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" \
|
||||||
"$PYDOCDIR/html/" \
|
"$PYDOCDIR/html/" \
|
||||||
delta@py.delta.chat:build/${BRANCH}
|
delta@py.delta.chat:build/${BRANCH}
|
||||||
|
|
||||||
# C docs to c.delta.chat
|
# C docs to c.delta.chat
|
||||||
#rsync -avz \
|
ssh -o BatchMode=yes -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null delta@c.delta.chat mkdir -p build-c/${BRANCH}
|
||||||
# -e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" \
|
rsync -avz \
|
||||||
# "$DOXYDOCDIR/html/" \
|
--delete \
|
||||||
# delta@py.delta.chat:build-c/${BRANCH}
|
-e "ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null" \
|
||||||
|
"$DOXYDOCDIR/html/" \
|
||||||
|
delta@c.delta.chat:build-c/${BRANCH}
|
||||||
|
|
||||||
echo -----------------------
|
echo -----------------------
|
||||||
echo upload wheels
|
echo upload wheels
|
||||||
@@ -34,7 +37,7 @@ echo -----------------------
|
|||||||
# Bundle external shared libraries into the wheels
|
# Bundle external shared libraries into the wheels
|
||||||
pushd $WHEELHOUSEDIR
|
pushd $WHEELHOUSEDIR
|
||||||
|
|
||||||
pip3 install -U setuptools
|
pip3 install -U pip setuptools
|
||||||
pip3 install devpi-client
|
pip3 install devpi-client
|
||||||
devpi use https://m.devpi.net
|
devpi use https://m.devpi.net
|
||||||
devpi login dc --password $DEVPI_LOGIN
|
devpi login dc --password $DEVPI_LOGIN
|
||||||
@@ -46,6 +49,9 @@ devpi use dc/$N_BRANCH || {
|
|||||||
devpi use dc/$N_BRANCH
|
devpi use dc/$N_BRANCH
|
||||||
}
|
}
|
||||||
devpi index $N_BRANCH bases=/root/pypi
|
devpi index $N_BRANCH bases=/root/pypi
|
||||||
devpi upload deltachat*.whl
|
devpi upload deltachat*
|
||||||
|
|
||||||
popd
|
popd
|
||||||
|
|
||||||
|
# remove devpi non-master dc indices if thy are too old
|
||||||
|
python ci_scripts/cleanup_devpi_indices.py
|
||||||
|
|||||||
72
ci_scripts/cleanup_devpi_indices.py
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
"""
|
||||||
|
Remove old "dc" indices except for master which always stays.
|
||||||
|
|
||||||
|
"""
|
||||||
|
from requests import Session
|
||||||
|
import datetime
|
||||||
|
import sys
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
MAXDAYS=7
|
||||||
|
|
||||||
|
session = Session()
|
||||||
|
session.headers["Accept"] = "application/json"
|
||||||
|
|
||||||
|
|
||||||
|
def get_indexes(baseurl, username):
|
||||||
|
response = session.get(baseurl + username)
|
||||||
|
assert response.status_code == 200
|
||||||
|
result = response.json()["result"]
|
||||||
|
return result["indexes"]
|
||||||
|
|
||||||
|
|
||||||
|
def get_projectnames(baseurl, username, indexname):
|
||||||
|
response = session.get(baseurl + username + "/" + indexname)
|
||||||
|
assert response.status_code == 200
|
||||||
|
result = response.json()["result"]
|
||||||
|
return result["projects"]
|
||||||
|
|
||||||
|
|
||||||
|
def get_release_dates(baseurl, username, indexname, projectname):
|
||||||
|
response = session.get(baseurl + username + "/" + indexname + "/" + projectname)
|
||||||
|
assert response.status_code == 200
|
||||||
|
result = response.json()["result"]
|
||||||
|
dates = set()
|
||||||
|
for value in result.values():
|
||||||
|
if "+links" not in value:
|
||||||
|
continue
|
||||||
|
for link in value["+links"]:
|
||||||
|
for log in link["log"]:
|
||||||
|
dates.add(tuple(log["when"]))
|
||||||
|
return dates
|
||||||
|
|
||||||
|
|
||||||
|
def run():
|
||||||
|
baseurl = "https://m.devpi.net/"
|
||||||
|
username = "dc"
|
||||||
|
for indexname in get_indexes(baseurl, username):
|
||||||
|
projectnames = get_projectnames(baseurl, username, indexname)
|
||||||
|
if indexname == "master" or not indexname:
|
||||||
|
continue
|
||||||
|
clear_index = not projectnames
|
||||||
|
for projectname in projectnames:
|
||||||
|
dates = get_release_dates(baseurl, username, indexname, projectname)
|
||||||
|
if not dates:
|
||||||
|
print(
|
||||||
|
"%s has no releases" % (baseurl + username + "/" + indexname),
|
||||||
|
file=sys.stderr)
|
||||||
|
date = datetime.datetime.now()
|
||||||
|
else:
|
||||||
|
date = datetime.datetime(*max(dates))
|
||||||
|
if (datetime.datetime.now() - date) > datetime.timedelta(days=MAXDAYS):
|
||||||
|
assert username and indexname
|
||||||
|
clear_index = True
|
||||||
|
break
|
||||||
|
if clear_index:
|
||||||
|
url = baseurl + username + "/" + indexname
|
||||||
|
subprocess.check_call(["devpi", "index", "-y", "--delete", url])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
run()
|
||||||
@@ -1,10 +1,15 @@
|
|||||||
FROM quay.io/pypa/manylinux1_x86_64
|
FROM quay.io/pypa/manylinux2010_x86_64
|
||||||
|
|
||||||
# Configure ld.so/ldconfig and pkg-config
|
# Configure ld.so/ldconfig and pkg-config
|
||||||
RUN echo /usr/local/lib64 > /etc/ld.so.conf.d/local.conf && \
|
RUN echo /usr/local/lib64 > /etc/ld.so.conf.d/local.conf && \
|
||||||
echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
|
echo /usr/local/lib >> /etc/ld.so.conf.d/local.conf
|
||||||
ENV PKG_CONFIG_PATH /usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig
|
ENV PKG_CONFIG_PATH /usr/local/lib64/pkgconfig:/usr/local/lib/pkgconfig
|
||||||
|
|
||||||
|
# Install a recent Perl, needed to install the openssl crate
|
||||||
|
ADD deps/build_perl.sh /builder/build_perl.sh
|
||||||
|
RUN rm /usr/bin/perl
|
||||||
|
RUN mkdir tmp1 && cd tmp1 && bash /builder/build_perl.sh && cd .. && rm -r tmp1
|
||||||
|
|
||||||
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
|
ENV PIP_DISABLE_PIP_VERSION_CHECK 1
|
||||||
|
|
||||||
# Install python tools (auditwheels,tox, ...)
|
# Install python tools (auditwheels,tox, ...)
|
||||||
@@ -14,12 +19,3 @@ RUN mkdir tmp1 && cd tmp1 && bash /builder/build_python.sh && cd .. && rm -r tmp
|
|||||||
# Install Rust nightly
|
# Install Rust nightly
|
||||||
ADD deps/build_rust.sh /builder/build_rust.sh
|
ADD deps/build_rust.sh /builder/build_rust.sh
|
||||||
RUN mkdir tmp1 && cd tmp1 && bash /builder/build_rust.sh && cd .. && rm -r tmp1
|
RUN mkdir tmp1 && cd tmp1 && bash /builder/build_rust.sh && cd .. && rm -r tmp1
|
||||||
|
|
||||||
# Install a recent Perl, needed to install OpenSSL
|
|
||||||
ADD deps/build_perl.sh /builder/build_perl.sh
|
|
||||||
RUN mkdir tmp1 && cd tmp1 && bash /builder/build_perl.sh && cd .. && rm -r tmp1
|
|
||||||
|
|
||||||
# Install OpenSSL
|
|
||||||
ADD deps/build_openssl.sh /builder/build_openssl.sh
|
|
||||||
RUN mkdir tmp1 && cd tmp1 && bash /builder/build_openssl.sh && cd .. && rm -r tmp1
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
PERL_VERSION=5.28.0
|
PERL_VERSION=5.30.0
|
||||||
PERL_SHA256=7e929f64d4cb0e9d1159d4a59fc89394e27fa1f7004d0836ca0d514685406ea8
|
# PERL_SHA256=7e929f64d4cb0e9d1159d4a59fc89394e27fa1f7004d0836ca0d514685406ea8
|
||||||
curl -O https://www.cpan.org/src/5.0/perl-${PERL_VERSION}.tar.gz
|
curl -O https://www.cpan.org/src/5.0/perl-${PERL_VERSION}.tar.gz
|
||||||
echo "${PERL_SHA256} perl-${PERL_VERSION}.tar.gz" | sha256sum -c -
|
# echo "${PERL_SHA256} perl-${PERL_VERSION}.tar.gz" | sha256sum -c -
|
||||||
tar xzf perl-${PERL_VERSION}.tar.gz
|
tar -xzf perl-${PERL_VERSION}.tar.gz
|
||||||
cd perl-${PERL_VERSION}
|
cd perl-${PERL_VERSION}
|
||||||
|
|
||||||
./Configure -de
|
./Configure -de
|
||||||
|
|||||||
@@ -3,9 +3,9 @@
|
|||||||
set -e -x
|
set -e -x
|
||||||
|
|
||||||
# Install Rust
|
# Install Rust
|
||||||
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain nightly-2019-07-10 -y
|
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.43.1-x86_64-unknown-linux-gnu -y
|
||||||
export PATH=/root/.cargo/bin:$PATH
|
export PATH=/root/.cargo/bin:$PATH
|
||||||
rustc --version
|
rustc --version
|
||||||
|
|
||||||
# remove some 300-400 MB that we don't need for automated builds
|
# remove some 300-400 MB that we don't need for automated builds
|
||||||
rm -rf /root/.rustup/toolchains/nightly-2019-07-10-x86_64-unknown-linux-gnu/share/
|
rm -rf /root/.rustup/toolchains/1.43.1-x86_64-unknown-linux-gnu/share
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
#!/bin/bash
|
|
||||||
#
|
|
||||||
# Build the Delta Chat C/Rust library
|
|
||||||
#
|
|
||||||
set -e -x
|
|
||||||
|
|
||||||
# perform clean build of core and install
|
|
||||||
export TOXWORKDIR=.docker-tox
|
|
||||||
|
|
||||||
# build core library
|
|
||||||
|
|
||||||
cargo build --release -p deltachat_ffi
|
|
||||||
|
|
||||||
# configure access to a base python and
|
|
||||||
# to several python interpreters needed by tox below
|
|
||||||
export PATH=$PATH:/opt/python/cp35-cp35m/bin
|
|
||||||
export PYTHONDONTWRITEBYTECODE=1
|
|
||||||
pushd /bin
|
|
||||||
ln -s /opt/python/cp27-cp27m/bin/python2.7
|
|
||||||
ln -s /opt/python/cp36-cp36m/bin/python3.6
|
|
||||||
ln -s /opt/python/cp37-cp37m/bin/python3.7
|
|
||||||
popd
|
|
||||||
|
|
||||||
#
|
|
||||||
# run python tests
|
|
||||||
#
|
|
||||||
|
|
||||||
if [ -n "$TESTS" ]; then
|
|
||||||
|
|
||||||
echo ----------------
|
|
||||||
echo run python tests
|
|
||||||
echo ----------------
|
|
||||||
|
|
||||||
pushd python
|
|
||||||
# first run all tests ...
|
|
||||||
rm -rf tests/__pycache__
|
|
||||||
rm -rf src/deltachat/__pycache__
|
|
||||||
export PYTHONDONTWRITEBYTECODE=1
|
|
||||||
tox --workdir "$TOXWORKDIR" -e py27,py35,py36,py37
|
|
||||||
popd
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
if [ -n "$DOCS" ]; then
|
|
||||||
echo -----------------------
|
|
||||||
echo generating python docs
|
|
||||||
echo -----------------------
|
|
||||||
(cd python && tox --workdir "$TOXWORKDIR" -e doc)
|
|
||||||
fi
|
|
||||||
9
ci_scripts/manual_remote_tests.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -xe
|
||||||
|
export CIRCLE_JOB=remote_tests_${1:?need to specify 'rust' or 'python'}
|
||||||
|
export CIRCLE_BUILD_NUM=$USER
|
||||||
|
export CIRCLE_BRANCH=`git branch | grep \* | cut -d ' ' -f2`
|
||||||
|
export CIRCLE_PROJECT_REPONAME=$(basename `git rev-parse --show-toplevel`)
|
||||||
|
|
||||||
|
time bash ci_scripts/$CIRCLE_JOB.sh
|
||||||
77
ci_scripts/old/gh-actions-rust.yml
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
name: CI
|
||||||
|
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
|
||||||
|
env:
|
||||||
|
RUSTFLAGS: -Dwarnings
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build_and_test:
|
||||||
|
name: Build and test
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macOS-latest]
|
||||||
|
rust: [nightly]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
|
||||||
|
- name: Install ${{ matrix.rust }}
|
||||||
|
uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
toolchain: ${{ matrix.rust }}
|
||||||
|
override: true
|
||||||
|
|
||||||
|
- name: check
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
if: matrix.rust == 'nightly'
|
||||||
|
with:
|
||||||
|
command: check
|
||||||
|
args: --all --bins --examples --tests
|
||||||
|
|
||||||
|
- name: tests
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --all
|
||||||
|
|
||||||
|
- name: tests ignored
|
||||||
|
uses: actions-rs/cargo@v1
|
||||||
|
with:
|
||||||
|
command: test
|
||||||
|
args: --all --release -- --ignored
|
||||||
|
|
||||||
|
check_fmt:
|
||||||
|
name: Checking fmt and docs
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@master
|
||||||
|
|
||||||
|
- uses: actions-rs/toolchain@v1
|
||||||
|
with:
|
||||||
|
profile: minimal
|
||||||
|
toolchain: nightly
|
||||||
|
override: true
|
||||||
|
components: rustfmt
|
||||||
|
|
||||||
|
- name: fmt
|
||||||
|
run: cargo fmt --all -- --check
|
||||||
|
|
||||||
|
# clippy_check:
|
||||||
|
# name: Clippy check
|
||||||
|
# runs-on: ubuntu-latest
|
||||||
|
#
|
||||||
|
# steps:
|
||||||
|
# - uses: actions/checkout@v1
|
||||||
|
# - uses: actions-rs/toolchain@v1
|
||||||
|
# with:
|
||||||
|
# profile: minimal
|
||||||
|
# toolchain: nightly
|
||||||
|
# override: true
|
||||||
|
# components: clippy
|
||||||
|
#
|
||||||
|
# - name: clippy
|
||||||
|
# run: cargo clippy --all
|
||||||
61
ci_scripts/old/run-python.sh
Executable file
@@ -0,0 +1,61 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Build the Delta Chat C/Rust library typically run in a docker
|
||||||
|
# container that contains all library deps but should also work
|
||||||
|
# outside if you have the dependencies installed on your system.
|
||||||
|
|
||||||
|
set -e -x
|
||||||
|
|
||||||
|
# Perform clean build of core and install.
|
||||||
|
export TOXWORKDIR=.docker-tox
|
||||||
|
|
||||||
|
# install core lib
|
||||||
|
|
||||||
|
export PATH=/root/.cargo/bin:$PATH
|
||||||
|
cargo build --release -p deltachat_ffi
|
||||||
|
# cargo test --all --all-features
|
||||||
|
|
||||||
|
# Statically link against libdeltachat.a.
|
||||||
|
export DCC_RS_DEV=$(pwd)
|
||||||
|
|
||||||
|
# Configure access to a base python and to several python interpreters
|
||||||
|
# needed by tox below.
|
||||||
|
export PATH=$PATH:/opt/python/cp35-cp35m/bin
|
||||||
|
export PYTHONDONTWRITEBYTECODE=1
|
||||||
|
pushd /bin
|
||||||
|
ln -s /opt/python/cp27-cp27m/bin/python2.7
|
||||||
|
ln -s /opt/python/cp36-cp36m/bin/python3.6
|
||||||
|
ln -s /opt/python/cp37-cp37m/bin/python3.7
|
||||||
|
popd
|
||||||
|
|
||||||
|
if [ -n "$TESTS" ]; then
|
||||||
|
|
||||||
|
pushd python
|
||||||
|
# prepare a clean tox run
|
||||||
|
rm -rf tests/__pycache__
|
||||||
|
rm -rf src/deltachat/__pycache__
|
||||||
|
export PYTHONDONTWRITEBYTECODE=1
|
||||||
|
|
||||||
|
# run tox. The circle-ci project env-var-setting DCC_PY_LIVECONFIG
|
||||||
|
# allows running of "liveconfig" tests but for speed reasons
|
||||||
|
# we run them only for the highest python version we support
|
||||||
|
|
||||||
|
# we split out qr-tests run to minimize likelyness of flaky tests
|
||||||
|
# (some qr tests are pretty heavy in terms of send/received
|
||||||
|
# messages and rust's imap code likely has concurrency problems)
|
||||||
|
tox --workdir "$TOXWORKDIR" -e py37 -- --reruns 3 -k "not qr"
|
||||||
|
tox --workdir "$TOXWORKDIR" -e py37 -- --reruns 3 -k "qr"
|
||||||
|
unset DCC_PY_LIVECONFIG
|
||||||
|
unset DCC_NEW_TMP_EMAIL
|
||||||
|
tox --workdir "$TOXWORKDIR" -p4 -e lint,py35,py36,doc
|
||||||
|
tox --workdir "$TOXWORKDIR" -e auditwheels
|
||||||
|
popd
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# if [ -n "$DOCS" ]; then
|
||||||
|
# echo -----------------------
|
||||||
|
# echo generating python docs
|
||||||
|
# echo -----------------------
|
||||||
|
# (cd python && tox --workdir "$TOXWORKDIR" -e doc)
|
||||||
|
# fi
|
||||||
51
ci_scripts/remote_python_packaging.sh
Executable file
@@ -0,0 +1,51 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export BRANCH=${CIRCLE_BRANCH:?branch to build}
|
||||||
|
export REPONAME=${CIRCLE_PROJECT_REPONAME:?repository name}
|
||||||
|
export SSHTARGET=${SSHTARGET-ci@b1.delta.chat}
|
||||||
|
|
||||||
|
# we construct the BUILDDIR such that we can easily share the
|
||||||
|
# CARGO_TARGET_DIR between runs ("..")
|
||||||
|
export BUILDDIR=ci_builds/$REPONAME/$BRANCH/${CIRCLE_JOB:?jobname}/${CIRCLE_BUILD_NUM:?circle-build-number}
|
||||||
|
|
||||||
|
echo "--- Copying files to $SSHTARGET:$BUILDDIR"
|
||||||
|
|
||||||
|
set -xe
|
||||||
|
|
||||||
|
ssh -oBatchMode=yes -oStrictHostKeyChecking=no $SSHTARGET mkdir -p "$BUILDDIR"
|
||||||
|
git ls-files >.rsynclist
|
||||||
|
# we seem to need .git for setuptools_scm versioning
|
||||||
|
find .git >>.rsynclist
|
||||||
|
rsync --delete --files-from=.rsynclist -az ./ "$SSHTARGET:$BUILDDIR"
|
||||||
|
|
||||||
|
set +x
|
||||||
|
|
||||||
|
# we have to create a remote file for the remote-docker run
|
||||||
|
# so we can do a simple ssh command with a TTY
|
||||||
|
# so that when our job dies, all container-runs are aborted.
|
||||||
|
# sidenote: the circle-ci machinery will kill ongoing jobs
|
||||||
|
# if there are new commits and we want to ensure that
|
||||||
|
# everything is terminated/cleaned up and we have no orphaned
|
||||||
|
# useless still-running docker-containers consuming resources.
|
||||||
|
|
||||||
|
ssh $SSHTARGET bash -c "cat >$BUILDDIR/exec_docker_run" <<_HERE
|
||||||
|
set +x -e
|
||||||
|
cd $BUILDDIR
|
||||||
|
export DCC_PY_LIVECONFIG=$DCC_PY_LIVECONFIG
|
||||||
|
export DCC_NEW_TMP_EMAIL=$DCC_NEW_TMP_EMAIL
|
||||||
|
set -x
|
||||||
|
|
||||||
|
# run everything else inside docker
|
||||||
|
docker run -e DCC_NEW_TMP_EMAIL -e DCC_PY_LIVECONFIG \
|
||||||
|
--rm -it -v \$(pwd):/mnt -w /mnt \
|
||||||
|
deltachat/coredeps ci_scripts/run_all.sh
|
||||||
|
|
||||||
|
_HERE
|
||||||
|
|
||||||
|
echo "--- Running $CIRCLE_JOB remotely"
|
||||||
|
|
||||||
|
ssh -t $SSHTARGET bash "$BUILDDIR/exec_docker_run"
|
||||||
|
mkdir -p workspace
|
||||||
|
rsync -avz "$SSHTARGET:$BUILDDIR/python/.docker-tox/wheelhouse/*manylinux201*" workspace/wheelhouse/
|
||||||
|
rsync -avz "$SSHTARGET:$BUILDDIR/python/.docker-tox/dist/*" workspace/wheelhouse/
|
||||||
|
rsync -avz "$SSHTARGET:$BUILDDIR/python/doc/_build/" workspace/py-docs
|
||||||
47
ci_scripts/remote_tests_python.sh
Executable file
@@ -0,0 +1,47 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export BRANCH=${CIRCLE_BRANCH:?branch to build}
|
||||||
|
export REPONAME=${CIRCLE_PROJECT_REPONAME:?repository name}
|
||||||
|
export SSHTARGET=${SSHTARGET-ci@b1.delta.chat}
|
||||||
|
|
||||||
|
# we construct the BUILDDIR such that we can easily share the
|
||||||
|
# CARGO_TARGET_DIR between runs ("..")
|
||||||
|
export BUILDDIR=ci_builds/$REPONAME/$BRANCH/${CIRCLE_JOB:?jobname}/${CIRCLE_BUILD_NUM:?circle-build-number}
|
||||||
|
|
||||||
|
echo "--- Copying files to $SSHTARGET:$BUILDDIR"
|
||||||
|
|
||||||
|
set -xe
|
||||||
|
|
||||||
|
ssh -oBatchMode=yes -oStrictHostKeyChecking=no $SSHTARGET mkdir -p "$BUILDDIR"
|
||||||
|
git ls-files >.rsynclist
|
||||||
|
# we seem to need .git for setuptools_scm versioning
|
||||||
|
find .git >>.rsynclist
|
||||||
|
rsync --delete --files-from=.rsynclist -az ./ "$SSHTARGET:$BUILDDIR"
|
||||||
|
|
||||||
|
set +x
|
||||||
|
|
||||||
|
echo "--- Running $CIRCLE_JOB remotely"
|
||||||
|
|
||||||
|
ssh $SSHTARGET <<_HERE
|
||||||
|
set +x -e
|
||||||
|
cd $BUILDDIR
|
||||||
|
# let's share the target dir with our last run on this branch/job-type
|
||||||
|
# cargo will make sure to block/unblock us properly
|
||||||
|
export CARGO_TARGET_DIR=\`pwd\`/../target
|
||||||
|
export TARGET=release
|
||||||
|
export DCC_PY_LIVECONFIG=$DCC_PY_LIVECONFIG
|
||||||
|
export DCC_NEW_TMP_EMAIL=$DCC_NEW_TMP_EMAIL
|
||||||
|
|
||||||
|
#we rely on tox/virtualenv being available in the host
|
||||||
|
#rm -rf virtualenv venv
|
||||||
|
#virtualenv -q -p python3.7 venv
|
||||||
|
#source venv/bin/activate
|
||||||
|
#pip install -q tox virtualenv
|
||||||
|
|
||||||
|
set -x
|
||||||
|
which python
|
||||||
|
source \$HOME/venv/bin/activate
|
||||||
|
which python
|
||||||
|
|
||||||
|
bash ci_scripts/run-python-test.sh
|
||||||
|
_HERE
|
||||||
32
ci_scripts/remote_tests_rust.sh
Executable file
@@ -0,0 +1,32 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export BRANCH=${CIRCLE_BRANCH:?branch to build}
|
||||||
|
export REPONAME=${CIRCLE_PROJECT_REPONAME:?repository name}
|
||||||
|
export SSHTARGET=${SSHTARGET-ci@b1.delta.chat}
|
||||||
|
|
||||||
|
# we construct the BUILDDIR such that we can easily share the
|
||||||
|
# CARGO_TARGET_DIR between runs ("..")
|
||||||
|
export BUILDDIR=ci_builds/$REPONAME/$BRANCH/${CIRCLE_JOB:?jobname}/${CIRCLE_BUILD_NUM:?circle-build-number}
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
echo "--- Copying files to $SSHTARGET:$BUILDDIR"
|
||||||
|
|
||||||
|
ssh -oBatchMode=yes -oStrictHostKeyChecking=no $SSHTARGET mkdir -p "$BUILDDIR"
|
||||||
|
git ls-files >.rsynclist
|
||||||
|
rsync --delete --files-from=.rsynclist -az ./ "$SSHTARGET:$BUILDDIR"
|
||||||
|
|
||||||
|
echo "--- Running $CIRCLE_JOB remotely"
|
||||||
|
|
||||||
|
ssh $SSHTARGET <<_HERE
|
||||||
|
set +x -e
|
||||||
|
cd $BUILDDIR
|
||||||
|
# let's share the target dir with our last run on this branch/job-type
|
||||||
|
# cargo will make sure to block/unblock us properly
|
||||||
|
export CARGO_TARGET_DIR=\`pwd\`/../target
|
||||||
|
export TARGET=x86_64-unknown-linux-gnu
|
||||||
|
export RUSTC_WRAPPER=sccache
|
||||||
|
|
||||||
|
bash ci_scripts/run-rust-test.sh
|
||||||
|
_HERE
|
||||||
|
|
||||||
6
ci_scripts/run-doxygen.sh
Executable file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -ex
|
||||||
|
|
||||||
|
cd deltachat-ffi
|
||||||
|
PROJECT_NUMBER=$(git log -1 --format "%h (%cd)") doxygen
|
||||||
24
ci_scripts/run-python-test.sh
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# Run functional tests for Delta Chat core using the python bindings
|
||||||
|
# and tox/pytest.
|
||||||
|
|
||||||
|
set -e -x
|
||||||
|
|
||||||
|
# for core-building and python install step
|
||||||
|
export DCC_RS_TARGET=debug
|
||||||
|
export DCC_RS_DEV=`pwd`
|
||||||
|
|
||||||
|
cd python
|
||||||
|
|
||||||
|
python install_python_bindings.py onlybuild
|
||||||
|
|
||||||
|
# remove and inhibit writing PYC files
|
||||||
|
rm -rf tests/__pycache__
|
||||||
|
rm -rf src/deltachat/__pycache__
|
||||||
|
export PYTHONDONTWRITEBYTECODE=1
|
||||||
|
|
||||||
|
# run python tests (tox invokes pytest to run tests in python/tests)
|
||||||
|
#TOX_PARALLEL_NO_SPINNER=1 tox -e lint,doc
|
||||||
|
tox -e lint
|
||||||
|
tox -e doc,py37
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
set -ex
|
set -ex
|
||||||
|
|
||||||
export RUST_TEST_THREADS=1
|
#export RUST_TEST_THREADS=1
|
||||||
export RUST_BACKTRACE=1
|
export RUST_BACKTRACE=1
|
||||||
export RUSTFLAGS='--deny warnings'
|
export RUSTFLAGS='--deny warnings'
|
||||||
export OPT="--target=$TARGET"
|
export OPT="--target=$TARGET"
|
||||||
@@ -31,16 +31,15 @@ fi
|
|||||||
if [[ $NORUN == "1" ]]; then
|
if [[ $NORUN == "1" ]]; then
|
||||||
export CARGO_SUBCMD="build"
|
export CARGO_SUBCMD="build"
|
||||||
else
|
else
|
||||||
export CARGO_SUBCMD="test"
|
export CARGO_SUBCMD="test --all"
|
||||||
export OPT="${OPT} "
|
export OPT="${OPT} "
|
||||||
export OPT_RELEASE="${OPT_RELEASE} "
|
export OPT_RELEASE="${OPT_RELEASE} "
|
||||||
export OPT_RELEASE_IGNORED="${OPT_RELEASE} -- --ignored"
|
export OPT_RELEASE_IGNORED="${OPT_RELEASE} -- --ignored"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run all the test configurations:
|
# Run all the test configurations
|
||||||
|
# RUSTC_WRAPPER=SCCACHE seems to destroy parallelism / prolong the test
|
||||||
|
unset RUSTC_WRAPPER
|
||||||
$CARGO_CMD $CARGO_SUBCMD $OPT
|
$CARGO_CMD $CARGO_SUBCMD $OPT
|
||||||
$CARGO_CMD $CARGO_SUBCMD $OPT_RELEASE
|
$CARGO_CMD $CARGO_SUBCMD $OPT_RELEASE
|
||||||
$CARGO_CMD $CARGO_SUBCMD $OPT_RELEASE_IGNORED
|
$CARGO_CMD $CARGO_SUBCMD $OPT_RELEASE_IGNORED
|
||||||
|
|
||||||
# Build the ffi lib
|
|
||||||
$CARGO_CMD $CARGO_SUBCMD $OPT_FFI_RELEASE
|
|
||||||
@@ -1,15 +1,13 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# Build the Delta Chat C/Rust library typically run in a docker
|
# Build the Delta Chat Core Rust library, Python wheels and docs
|
||||||
# container that contains all library deps but should also work
|
|
||||||
# outside if you have the dependencies installed on your system.
|
|
||||||
|
|
||||||
set -e -x
|
set -e -x
|
||||||
|
|
||||||
# Perform clean build of core and install.
|
# Perform clean build of core and install.
|
||||||
export TOXWORKDIR=.docker-tox
|
export TOXWORKDIR=.docker-tox
|
||||||
|
|
||||||
# install core lib
|
# compile core lib
|
||||||
|
|
||||||
export PATH=/root/.cargo/bin:$PATH
|
export PATH=/root/.cargo/bin:$PATH
|
||||||
cargo build --release -p deltachat_ffi
|
cargo build --release -p deltachat_ffi
|
||||||
@@ -23,32 +21,30 @@ export DCC_RS_DEV=$(pwd)
|
|||||||
export PATH=$PATH:/opt/python/cp35-cp35m/bin
|
export PATH=$PATH:/opt/python/cp35-cp35m/bin
|
||||||
export PYTHONDONTWRITEBYTECODE=1
|
export PYTHONDONTWRITEBYTECODE=1
|
||||||
pushd /bin
|
pushd /bin
|
||||||
ln -s /opt/python/cp27-cp27m/bin/python2.7
|
rm -f python3.5
|
||||||
|
ln -s /opt/python/cp35-cp35m/bin/python3.5
|
||||||
ln -s /opt/python/cp36-cp36m/bin/python3.6
|
ln -s /opt/python/cp36-cp36m/bin/python3.6
|
||||||
ln -s /opt/python/cp37-cp37m/bin/python3.7
|
ln -s /opt/python/cp37-cp37m/bin/python3.7
|
||||||
|
ln -s /opt/python/cp38-cp38/bin/python3.8
|
||||||
popd
|
popd
|
||||||
|
|
||||||
if [ -n "$TESTS" ]; then
|
pushd python
|
||||||
|
# prepare a clean tox run
|
||||||
|
rm -rf tests/__pycache__
|
||||||
|
rm -rf src/deltachat/__pycache__
|
||||||
|
mkdir -p $TOXWORKDIR
|
||||||
|
|
||||||
pushd python
|
# disable live-account testing to speed up test runs and wheel building
|
||||||
# prepare a clean tox run
|
# XXX we may switch on some live-tests on for better ensurances
|
||||||
rm -rf tests/__pycache__
|
# Note that the independent remote_tests_python step does all kinds of
|
||||||
rm -rf src/deltachat/__pycache__
|
# live-testing already.
|
||||||
export PYTHONDONTWRITEBYTECODE=1
|
unset DCC_PY_LIVECONFIG
|
||||||
|
unset DCC_NEW_TMP_EMAIL
|
||||||
# run tox
|
tox --workdir "$TOXWORKDIR" -e py35,py36,py37,py38,auditwheels
|
||||||
# XXX we don't run liveconfig tests because they hang sometimes
|
popd
|
||||||
# see https://github.com/deltachat/deltachat-core-rust/issues/331
|
|
||||||
# unset DCC_PY_LIVECONFIG
|
|
||||||
|
|
||||||
tox --workdir "$TOXWORKDIR" -e lint,py27,py35,py36,py37,auditwheels
|
|
||||||
popd
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
|
||||||
if [ -n "$DOCS" ]; then
|
echo -----------------------
|
||||||
echo -----------------------
|
echo generating python docs
|
||||||
echo generating python docs
|
echo -----------------------
|
||||||
echo -----------------------
|
(cd python && tox --workdir "$TOXWORKDIR" -e doc)
|
||||||
(cd python && tox --workdir "$TOXWORKDIR" -e doc)
|
|
||||||
fi
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "deltachat_ffi"
|
name = "deltachat_ffi"
|
||||||
version = "1.0.0-alpha.4"
|
version = "1.39.0"
|
||||||
description = "Deltachat FFI"
|
description = "Deltachat FFI"
|
||||||
authors = ["dignifiedquire <dignifiedquire@gmail.com>"]
|
authors = ["Delta Chat Developers (ML) <delta@codespeak.net>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
license = "MIT OR Apache-2.0"
|
license = "MPL-2.0"
|
||||||
|
|
||||||
keywords = ["deltachat", "chat", "openpgp", "email", "encryption"]
|
keywords = ["deltachat", "chat", "openpgp", "email", "encryption"]
|
||||||
categories = ["cryptography", "std", "email"]
|
categories = ["cryptography", "std", "email"]
|
||||||
@@ -19,9 +19,13 @@ deltachat = { path = "../", default-features = false }
|
|||||||
libc = "0.2"
|
libc = "0.2"
|
||||||
human-panic = "1.0.1"
|
human-panic = "1.0.1"
|
||||||
num-traits = "0.2.6"
|
num-traits = "0.2.6"
|
||||||
|
serde_json = "1.0"
|
||||||
|
async-std = "1.6.0"
|
||||||
|
anyhow = "1.0.28"
|
||||||
|
thiserror = "1.0.14"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
default = ["vendored", "nightly", "ringbuf"]
|
default = ["vendored"]
|
||||||
vendored = ["deltachat/vendored"]
|
vendored = ["deltachat/vendored"]
|
||||||
nightly = ["deltachat/nightly"]
|
nightly = ["deltachat/nightly"]
|
||||||
ringbuf = ["deltachat/ringbuf"]
|
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
use crate::location::Location;
|
use crate::location::Location;
|
||||||
use crate::types::*;
|
|
||||||
|
|
||||||
/* * the structure behind dc_array_t */
|
/* * the structure behind dc_array_t */
|
||||||
#[derive(Clone)]
|
#[derive(Debug, Clone)]
|
||||||
#[allow(non_camel_case_types)]
|
|
||||||
pub enum dc_array_t {
|
pub enum dc_array_t {
|
||||||
Locations(Vec<Location>),
|
Locations(Vec<Location>),
|
||||||
Uint(Vec<u32>),
|
Uint(Vec<u32>),
|
||||||
@@ -19,7 +17,7 @@ impl dc_array_t {
|
|||||||
dc_array_t::Locations(Vec::with_capacity(capacity))
|
dc_array_t::Locations(Vec::with_capacity(capacity))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_id(&mut self, item: uint32_t) {
|
pub fn add_id(&mut self, item: u32) {
|
||||||
if let Self::Uint(array) = self {
|
if let Self::Uint(array) = self {
|
||||||
array.push(item);
|
array.push(item);
|
||||||
} else {
|
} else {
|
||||||
@@ -35,10 +33,10 @@ impl dc_array_t {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_id(&self, index: usize) -> uint32_t {
|
pub fn get_id(&self, index: usize) -> u32 {
|
||||||
match self {
|
match self {
|
||||||
Self::Locations(array) => array[index].location_id,
|
Self::Locations(array) => array[index].location_id,
|
||||||
Self::Uint(array) => array[index] as uint32_t,
|
Self::Uint(array) => array[index] as u32,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
410
deltachat-ffi/src/string.rs
Normal file
@@ -0,0 +1,410 @@
|
|||||||
|
use std::ffi::{CStr, CString};
|
||||||
|
use std::ptr;
|
||||||
|
|
||||||
|
/// Duplicates a string
|
||||||
|
///
|
||||||
|
/// returns an empty string if NULL is given, never returns NULL (exits on errors)
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```rust,norun
|
||||||
|
/// use crate::string::{dc_strdup, to_string_lossy};
|
||||||
|
/// unsafe {
|
||||||
|
/// let str_a = b"foobar\x00" as *const u8 as *const libc::c_char;
|
||||||
|
/// let str_a_copy = dc_strdup(str_a);
|
||||||
|
/// assert_eq!(to_string_lossy(str_a_copy), "foobar");
|
||||||
|
/// assert_ne!(str_a, str_a_copy);
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
unsafe fn dc_strdup(s: *const libc::c_char) -> *mut libc::c_char {
|
||||||
|
let ret: *mut libc::c_char;
|
||||||
|
if !s.is_null() {
|
||||||
|
ret = libc::strdup(s);
|
||||||
|
assert!(!ret.is_null());
|
||||||
|
} else {
|
||||||
|
ret = libc::calloc(1, 1) as *mut libc::c_char;
|
||||||
|
assert!(!ret.is_null());
|
||||||
|
}
|
||||||
|
|
||||||
|
ret
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Error type for the [OsStrExt] trait
|
||||||
|
#[derive(Debug, PartialEq, thiserror::Error)]
|
||||||
|
pub(crate) enum CStringError {
|
||||||
|
/// The string contains an interior null byte
|
||||||
|
#[error("String contains an interior null byte")]
|
||||||
|
InteriorNullByte,
|
||||||
|
/// The string is not valid Unicode
|
||||||
|
#[error("String is not valid unicode")]
|
||||||
|
NotUnicode,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Extra convenience methods on [std::ffi::OsStr] to work with `*libc::c_char`.
|
||||||
|
///
|
||||||
|
/// The primary function of this trait is to more easily convert
|
||||||
|
/// [OsStr], [OsString] or [Path] into pointers to C strings. This always
|
||||||
|
/// allocates a new string since it is very common for the source
|
||||||
|
/// string not to have the required terminal null byte.
|
||||||
|
///
|
||||||
|
/// It is implemented for `AsRef<std::ffi::OsStr>>` trait, which
|
||||||
|
/// allows any type which implements this trait to transparently use
|
||||||
|
/// this. This is how the conversion for [Path] works.
|
||||||
|
///
|
||||||
|
/// [OsStr]: std::ffi::OsStr
|
||||||
|
/// [OsString]: std::ffi::OsString
|
||||||
|
/// [Path]: std::path::Path
|
||||||
|
///
|
||||||
|
/// # Example
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// use deltachat::dc_tools::{dc_strdup, OsStrExt};
|
||||||
|
/// let path = std::path::Path::new("/some/path");
|
||||||
|
/// let path_c = path.to_c_string().unwrap();
|
||||||
|
/// unsafe {
|
||||||
|
/// let mut c_ptr: *mut libc::c_char = dc_strdup(path_c.as_ptr());
|
||||||
|
/// }
|
||||||
|
/// ```
|
||||||
|
pub(crate) trait OsStrExt {
|
||||||
|
/// Convert a [std::ffi::OsStr] to an [std::ffi::CString]
|
||||||
|
///
|
||||||
|
/// This is useful to convert e.g. a [std::path::Path] to
|
||||||
|
/// [*libc::c_char] by using
|
||||||
|
/// [Path::as_os_str()](std::path::Path::as_os_str) and
|
||||||
|
/// [CStr::as_ptr()](std::ffi::CStr::as_ptr).
|
||||||
|
///
|
||||||
|
/// This returns [CString] and not [&CStr] because not all [OsStr]
|
||||||
|
/// slices end with a null byte, particularly those coming from
|
||||||
|
/// [Path] do not have a null byte and having to handle this as
|
||||||
|
/// the caller would defeat the point of this function.
|
||||||
|
///
|
||||||
|
/// On Windows this requires that the [OsStr] contains valid
|
||||||
|
/// unicode, which should normally be the case for a [Path].
|
||||||
|
///
|
||||||
|
/// [CString]: std::ffi::CString
|
||||||
|
/// [CStr]: std::ffi::CStr
|
||||||
|
/// [OsStr]: std::ffi::OsStr
|
||||||
|
/// [Path]: std::path::Path
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// Since a C `*char` is terminated by a NULL byte this conversion
|
||||||
|
/// will fail, when the [OsStr] has an interior null byte. The
|
||||||
|
/// function will return
|
||||||
|
/// `[Err]([CStringError::InteriorNullByte])`. When converting
|
||||||
|
/// from a [Path] it should be safe to
|
||||||
|
/// [`.unwrap()`](std::result::Result::unwrap) this anyway since a
|
||||||
|
/// [Path] should not contain interior null bytes.
|
||||||
|
///
|
||||||
|
/// On windows when the string contains invalid Unicode
|
||||||
|
/// `[Err]([CStringError::NotUnicode])` is returned.
|
||||||
|
fn to_c_string(&self) -> Result<CString, CStringError>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: AsRef<std::ffi::OsStr>> OsStrExt for T {
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
fn to_c_string(&self) -> Result<CString, CStringError> {
|
||||||
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
CString::new(self.as_ref().as_bytes()).map_err(|err| match err {
|
||||||
|
std::ffi::NulError { .. } => CStringError::InteriorNullByte,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
fn to_c_string(&self) -> Result<CString, CStringError> {
|
||||||
|
os_str_to_c_string_unicode(&self)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implementation for os_str_to_c_string on windows.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn os_str_to_c_string_unicode(
|
||||||
|
os_str: &dyn AsRef<std::ffi::OsStr>,
|
||||||
|
) -> Result<CString, CStringError> {
|
||||||
|
match os_str.as_ref().to_str() {
|
||||||
|
Some(val) => CString::new(val.as_bytes()).map_err(|err| match err {
|
||||||
|
std::ffi::NulError { .. } => CStringError::InteriorNullByte,
|
||||||
|
}),
|
||||||
|
None => Err(CStringError::NotUnicode),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience methods/associated functions for working with [CString]
|
||||||
|
trait CStringExt {
|
||||||
|
/// Create a new [CString], best effort
|
||||||
|
///
|
||||||
|
/// Like the [to_string_lossy] this doesn't give up in the face of
|
||||||
|
/// bad input (embedded null bytes in this case) instead it does
|
||||||
|
/// the best it can by stripping the embedded null bytes.
|
||||||
|
fn new_lossy<T: Into<Vec<u8>>>(t: T) -> CString {
|
||||||
|
let mut s = t.into();
|
||||||
|
s.retain(|&c| c != 0);
|
||||||
|
CString::new(s).unwrap_or_default()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl CStringExt for CString {}
|
||||||
|
|
||||||
|
/// Convenience methods to turn strings into C strings.
|
||||||
|
///
|
||||||
|
/// To interact with (legacy) C APIs we often need to convert from
|
||||||
|
/// Rust strings to raw C strings. This can be clumsy to do correctly
|
||||||
|
/// and the compiler sometimes allows it in an unsafe way. These
|
||||||
|
/// methods make it more succinct and help you get it right.
|
||||||
|
pub(crate) trait Strdup {
|
||||||
|
/// Allocate a new raw C `*char` version of this string.
|
||||||
|
///
|
||||||
|
/// This allocates a new raw C string which must be freed using
|
||||||
|
/// `free`. It takes care of some common pitfalls with using
|
||||||
|
/// [CString.as_ptr].
|
||||||
|
///
|
||||||
|
/// [CString.as_ptr]: std::ffi::CString.as_ptr
|
||||||
|
///
|
||||||
|
/// # Panics
|
||||||
|
///
|
||||||
|
/// This function will panic when the original string contains an
|
||||||
|
/// interior null byte as this can not be represented in raw C
|
||||||
|
/// strings.
|
||||||
|
unsafe fn strdup(&self) -> *mut libc::c_char;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: AsRef<str>> Strdup for T {
|
||||||
|
unsafe fn strdup(&self) -> *mut libc::c_char {
|
||||||
|
let tmp = CString::new_lossy(self.as_ref());
|
||||||
|
dc_strdup(tmp.as_ptr())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// We can not implement for AsRef<OsStr> because we already implement
|
||||||
|
// AsRev<str> and this conflicts. So implement for Path directly.
|
||||||
|
impl Strdup for std::path::Path {
|
||||||
|
unsafe fn strdup(&self) -> *mut libc::c_char {
|
||||||
|
let tmp = self.to_c_string().unwrap_or_else(|_| CString::default());
|
||||||
|
dc_strdup(tmp.as_ptr())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convenience methods to turn optional strings into C strings.
|
||||||
|
///
|
||||||
|
/// This is the same as the [Strdup] trait but a different trait name
|
||||||
|
/// to work around the type system not allowing to implement [Strdup]
|
||||||
|
/// for `Option<impl Strdup>` When we already have an [Strdup] impl
|
||||||
|
/// for `AsRef<&str>`.
|
||||||
|
///
|
||||||
|
/// When the [Option] is [Option::Some] this behaves just like
|
||||||
|
/// [Strdup::strdup], when it is [Option::None] a null pointer is
|
||||||
|
/// returned.
|
||||||
|
pub(crate) trait OptStrdup {
|
||||||
|
/// Allocate a new raw C `*char` version of this string, or NULL.
|
||||||
|
///
|
||||||
|
/// See [Strdup::strdup] for details.
|
||||||
|
unsafe fn strdup(&self) -> *mut libc::c_char;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: AsRef<str>> OptStrdup for Option<T> {
|
||||||
|
unsafe fn strdup(&self) -> *mut libc::c_char {
|
||||||
|
match self {
|
||||||
|
Some(s) => {
|
||||||
|
let tmp = CString::new_lossy(s.as_ref());
|
||||||
|
dc_strdup(tmp.as_ptr())
|
||||||
|
}
|
||||||
|
None => ptr::null_mut(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn to_string_lossy(s: *const libc::c_char) -> String {
|
||||||
|
if s.is_null() {
|
||||||
|
return "".into();
|
||||||
|
}
|
||||||
|
|
||||||
|
let cstr = unsafe { CStr::from_ptr(s) };
|
||||||
|
|
||||||
|
cstr.to_string_lossy().to_string()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn to_opt_string_lossy(s: *const libc::c_char) -> Option<String> {
|
||||||
|
if s.is_null() {
|
||||||
|
return None;
|
||||||
|
}
|
||||||
|
|
||||||
|
Some(to_string_lossy(s))
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert a C `*char` pointer to a [std::path::Path] slice.
|
||||||
|
///
|
||||||
|
/// This converts a `*libc::c_char` pointer to a [Path] slice. This
|
||||||
|
/// essentially has to convert the pointer to [std::ffi::OsStr] to do
|
||||||
|
/// so and thus is the inverse of [OsStrExt::to_c_string]. Just like
|
||||||
|
/// [OsStrExt::to_c_string] requires valid Unicode on Windows, this
|
||||||
|
/// requires that the pointer contains valid UTF-8 on Windows.
|
||||||
|
///
|
||||||
|
/// Because this returns a reference the [Path] silce can not outlive
|
||||||
|
/// the original pointer.
|
||||||
|
///
|
||||||
|
/// [Path]: std::path::Path
|
||||||
|
#[cfg(not(target_os = "windows"))]
|
||||||
|
pub(crate) fn as_path<'a>(s: *const libc::c_char) -> &'a std::path::Path {
|
||||||
|
assert!(!s.is_null(), "cannot be used on null pointers");
|
||||||
|
use std::os::unix::ffi::OsStrExt;
|
||||||
|
unsafe {
|
||||||
|
let c_str = std::ffi::CStr::from_ptr(s).to_bytes();
|
||||||
|
let os_str = std::ffi::OsStr::from_bytes(c_str);
|
||||||
|
std::path::Path::new(os_str)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// as_path() implementation for windows, documented above.
|
||||||
|
#[cfg(target_os = "windows")]
|
||||||
|
pub(crate) fn as_path<'a>(s: *const libc::c_char) -> &'a std::path::Path {
|
||||||
|
as_path_unicode(s)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Implementation for as_path() on Windows.
|
||||||
|
//
|
||||||
|
// Having this as a separate function means it can be tested on unix
|
||||||
|
// too.
|
||||||
|
#[allow(dead_code)]
|
||||||
|
fn as_path_unicode<'a>(s: *const libc::c_char) -> &'a std::path::Path {
|
||||||
|
assert!(!s.is_null(), "cannot be used on null pointers");
|
||||||
|
|
||||||
|
let cstr = unsafe { CStr::from_ptr(s) };
|
||||||
|
let str = cstr.to_str().unwrap_or_else(|err| panic!("{}", err));
|
||||||
|
|
||||||
|
std::path::Path::new(str)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
use libc::{free, strcmp};
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_os_str_to_c_string_cwd() {
|
||||||
|
let some_dir = std::env::current_dir().unwrap();
|
||||||
|
some_dir.as_os_str().to_c_string().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_os_str_to_c_string_unicode() {
|
||||||
|
let some_str = String::from("/some/valid/utf8");
|
||||||
|
let some_dir = std::path::Path::new(&some_str);
|
||||||
|
assert_eq!(
|
||||||
|
some_dir.as_os_str().to_c_string().unwrap(),
|
||||||
|
CString::new("/some/valid/utf8").unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_os_str_to_c_string_nul() {
|
||||||
|
let some_str = std::ffi::OsString::from("foo\x00bar");
|
||||||
|
assert_eq!(
|
||||||
|
some_str.to_c_string().err().unwrap(),
|
||||||
|
CStringError::InteriorNullByte
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_path_to_c_string_cwd() {
|
||||||
|
let some_dir = std::env::current_dir().unwrap();
|
||||||
|
some_dir.to_c_string().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_path_to_c_string_unicode() {
|
||||||
|
let some_str = String::from("/some/valid/utf8");
|
||||||
|
let some_dir = std::path::Path::new(&some_str);
|
||||||
|
assert_eq!(
|
||||||
|
some_dir.as_os_str().to_c_string().unwrap(),
|
||||||
|
CString::new("/some/valid/utf8").unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_os_str_to_c_string_unicode_fn() {
|
||||||
|
let some_str = std::ffi::OsString::from("foo");
|
||||||
|
assert_eq!(
|
||||||
|
os_str_to_c_string_unicode(&some_str).unwrap(),
|
||||||
|
CString::new("foo").unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_path_to_c_string_unicode_fn() {
|
||||||
|
let some_str = String::from("/some/path");
|
||||||
|
let some_path = std::path::Path::new(&some_str);
|
||||||
|
assert_eq!(
|
||||||
|
os_str_to_c_string_unicode(&some_path).unwrap(),
|
||||||
|
CString::new("/some/path").unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_os_str_to_c_string_unicode_fn_nul() {
|
||||||
|
let some_str = std::ffi::OsString::from("fooz\x00bar");
|
||||||
|
assert_eq!(
|
||||||
|
os_str_to_c_string_unicode(&some_str).err().unwrap(),
|
||||||
|
CStringError::InteriorNullByte
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_as_path() {
|
||||||
|
let some_path = CString::new("/some/path").unwrap();
|
||||||
|
let ptr = some_path.as_ptr();
|
||||||
|
assert_eq!(as_path(ptr), std::ffi::OsString::from("/some/path"))
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_as_path_unicode_fn() {
|
||||||
|
let some_path = CString::new("/some/path").unwrap();
|
||||||
|
let ptr = some_path.as_ptr();
|
||||||
|
assert_eq!(as_path_unicode(ptr), std::ffi::OsString::from("/some/path"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_cstring_new_lossy() {
|
||||||
|
assert!(CString::new("hel\x00lo").is_err());
|
||||||
|
assert!(CString::new(String::from("hel\x00o")).is_err());
|
||||||
|
let r = CString::new("hello").unwrap();
|
||||||
|
assert_eq!(CString::new_lossy("hello"), r);
|
||||||
|
assert_eq!(CString::new_lossy("hel\x00lo"), r);
|
||||||
|
assert_eq!(CString::new_lossy(String::from("hello")), r);
|
||||||
|
assert_eq!(CString::new_lossy(String::from("hel\x00lo")), r);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_strdup_str() {
|
||||||
|
unsafe {
|
||||||
|
let s = "hello".strdup();
|
||||||
|
let cmp = strcmp(s, b"hello\x00" as *const u8 as *const libc::c_char);
|
||||||
|
free(s as *mut libc::c_void);
|
||||||
|
assert_eq!(cmp, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_strdup_string() {
|
||||||
|
unsafe {
|
||||||
|
let s = String::from("hello").strdup();
|
||||||
|
let cmp = strcmp(s, b"hello\x00" as *const u8 as *const libc::c_char);
|
||||||
|
free(s as *mut libc::c_void);
|
||||||
|
assert_eq!(cmp, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_strdup_opt_string() {
|
||||||
|
unsafe {
|
||||||
|
let s = Some("hello");
|
||||||
|
let c = s.strdup();
|
||||||
|
let cmp = strcmp(c, b"hello\x00" as *const u8 as *const libc::c_char);
|
||||||
|
free(c as *mut libc::c_void);
|
||||||
|
assert_eq!(cmp, 0);
|
||||||
|
|
||||||
|
let s: Option<&str> = None;
|
||||||
|
let c = s.strdup();
|
||||||
|
assert_eq!(c, ptr::null_mut());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "deltachat_derive"
|
name = "deltachat_derive"
|
||||||
version = "0.1.0"
|
version = "2.0.0"
|
||||||
authors = ["Dmitry Bogatov <KAction@debian.org>"]
|
authors = ["Delta Chat Developers (ML) <delta@codespeak.net>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
|
license = "MPL-2.0"
|
||||||
|
|
||||||
[lib]
|
[lib]
|
||||||
proc-macro = true
|
proc-macro = true
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
syn = "0.14.4"
|
syn = "1.0.13"
|
||||||
quote = "0.6.3"
|
quote = "1.0.2"
|
||||||
|
|||||||
@@ -3,42 +3,38 @@ extern crate proc_macro;
|
|||||||
|
|
||||||
use crate::proc_macro::TokenStream;
|
use crate::proc_macro::TokenStream;
|
||||||
use quote::quote;
|
use quote::quote;
|
||||||
use syn;
|
|
||||||
|
|
||||||
// For now, assume (not check) that these macroses are applied to enum without
|
// For now, assume (not check) that these macroses are applied to enum without
|
||||||
// data. If this assumption is violated, compiler error will point to
|
// data. If this assumption is violated, compiler error will point to
|
||||||
// generated code, which is not very user-friendly.
|
// generated code, which is not very user-friendly.
|
||||||
|
|
||||||
#[proc_macro_derive(ToSql)]
|
#[proc_macro_derive(Sqlx)]
|
||||||
pub fn to_sql_derive(input: TokenStream) -> TokenStream {
|
pub fn sqlx_derive(input: TokenStream) -> TokenStream {
|
||||||
let ast: syn::DeriveInput = syn::parse(input).unwrap();
|
let ast: syn::DeriveInput = syn::parse(input).unwrap();
|
||||||
let name = &ast.ident;
|
let name = &ast.ident;
|
||||||
|
|
||||||
let gen = quote! {
|
let gen = quote! {
|
||||||
impl rusqlite::types::ToSql for #name {
|
impl<'q> sqlx::encode::Encode<'q, sqlx::sqlite::Sqlite> for #name {
|
||||||
fn to_sql(&self) -> rusqlite::Result<rusqlite::types::ToSqlOutput> {
|
fn encode_by_ref(&self, buf: &mut Vec<sqlx::sqlite::SqliteArgumentValue<'q>>) -> sqlx::encode::IsNull {
|
||||||
let num = *self as i64;
|
num_traits::ToPrimitive::to_i32(self).expect("invalid type").encode(buf)
|
||||||
let value = rusqlite::types::Value::Integer(num);
|
|
||||||
let output = rusqlite::types::ToSqlOutput::Owned(value);
|
|
||||||
std::result::Result::Ok(output)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
gen.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[proc_macro_derive(FromSql)]
|
|
||||||
pub fn from_sql_derive(input: TokenStream) -> TokenStream {
|
|
||||||
let ast: syn::DeriveInput = syn::parse(input).unwrap();
|
|
||||||
let name = &ast.ident;
|
|
||||||
|
|
||||||
let gen = quote! {
|
|
||||||
impl rusqlite::types::FromSql for #name {
|
|
||||||
fn column_result(col: rusqlite::types::ValueRef) -> rusqlite::types::FromSqlResult<Self> {
|
|
||||||
let inner = rusqlite::types::FromSql::column_result(col)?;
|
|
||||||
num_traits::FromPrimitive::from_i64(inner).ok_or(rusqlite::types::FromSqlError::InvalidType)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
impl<'de> sqlx::decode::Decode<'de, sqlx::sqlite::Sqlite> for #name {
|
||||||
|
fn decode(value: sqlx::sqlite::SqliteValueRef) -> std::result::Result<Self, Box<dyn std::error::Error + 'static + Send + Sync>> {
|
||||||
|
let raw: i32 = sqlx::decode::Decode::decode(value)?;
|
||||||
|
|
||||||
|
Ok(num_traits::FromPrimitive::from_i32(raw).unwrap_or_default())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl sqlx::types::Type<sqlx::sqlite::Sqlite> for #name {
|
||||||
|
fn type_info() -> sqlx::sqlite::SqliteTypeInfo {
|
||||||
|
<i32 as sqlx::types::Type<_>>::type_info()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
gen.into()
|
gen.into()
|
||||||
}
|
}
|
||||||
|
|||||||
126
draft/group-sync.rst
Normal file
@@ -0,0 +1,126 @@
|
|||||||
|
|
||||||
|
Problem: missing eventual group consistency
|
||||||
|
--------------------------------------------
|
||||||
|
|
||||||
|
If group members are concurrently adding new members,
|
||||||
|
the new members will miss each other's additions, example:
|
||||||
|
|
||||||
|
- Alice and Bob are in a two-member group
|
||||||
|
|
||||||
|
- Alice adds Carol, concurrently Bob adds Doris
|
||||||
|
|
||||||
|
- Carol will see a three-member group (Alice, Bob, Carol),
|
||||||
|
Doris will see a different three-member group (Alice, Bob, Doris),
|
||||||
|
and only Alice and Bob will have all four members.
|
||||||
|
|
||||||
|
Note that for verified groups any mitigation mechanism likely
|
||||||
|
needs to make all clients to know who originally added a member.
|
||||||
|
|
||||||
|
|
||||||
|
solution: memorize+attach (possible encrypted) chat-meta mime messages
|
||||||
|
----------------------------------------------------------------------
|
||||||
|
|
||||||
|
For reference, please see https://github.com/deltachat/deltachat-core-rust/blob/master/spec.md#add-and-remove-members how MemberAdded/Removed messages are shaped.
|
||||||
|
|
||||||
|
|
||||||
|
- All Chat-Group-Member-Added/Removed messages are recorded in their
|
||||||
|
full raw (signed and encrypted) mime-format in the DB
|
||||||
|
|
||||||
|
- If an incoming member-add/member-delete messages has a member list
|
||||||
|
which is, apart from the added/removed member, not consistent
|
||||||
|
with our own view, broadcast a "Chat-Group-Member-Correction" message to
|
||||||
|
all members, attaching the original added/removed mime-message for all mismatching
|
||||||
|
contacts. If we have no relevant add/del information, don't send a
|
||||||
|
correction message out.
|
||||||
|
|
||||||
|
- Upong receiving added/removed attachments we don't do the
|
||||||
|
check_consistency+correction message dance.
|
||||||
|
This avoids recursion problems and hard-to-reason-about chatter.
|
||||||
|
|
||||||
|
Notes:
|
||||||
|
|
||||||
|
- mechanism works for both encrypted and unencrypted add/del messages
|
||||||
|
|
||||||
|
- we already have a "mime_headers" column in the DB for each incoming message.
|
||||||
|
We could extend it to also include the payload and store mime unconditionally
|
||||||
|
for member-added/removed messages.
|
||||||
|
|
||||||
|
- multiple member-added/removed messages can be attached in a single
|
||||||
|
correction message
|
||||||
|
|
||||||
|
- it is minimal on the number of overall messages to reach group consistency
|
||||||
|
(best-case: no extra messages, the ABCD case above: max two extra messages)
|
||||||
|
|
||||||
|
- somewhat backward compatible: older clients will probably ignore
|
||||||
|
messages which are signed by someone who is not the outer From-address.
|
||||||
|
|
||||||
|
- the correction-protocol also helps with dropped messages. If a member
|
||||||
|
did not see a member-added/removed message, the next member add/removed
|
||||||
|
message in the group will likely heal group consistency for this member.
|
||||||
|
|
||||||
|
- we can quite easily extend the mechanism to also provide the group-avatar or
|
||||||
|
other meta-information.
|
||||||
|
|
||||||
|
Discussions of variants
|
||||||
|
++++++++++++++++++++++++
|
||||||
|
|
||||||
|
- instead of acting on MemberAdded/Removed message we could send
|
||||||
|
corrections for any received message that addresses inconsistent group members but
|
||||||
|
a) this would delay group-membership healing
|
||||||
|
b) could lead to a lot of members sending corrections
|
||||||
|
|
||||||
|
- instead of broadcasting correction messages we could only send it to
|
||||||
|
the sender of the inconsistent member-added/removed message.
|
||||||
|
A receiver of such a correction message would then need to forward
|
||||||
|
the message to the members it thinks also have an inconsistent view.
|
||||||
|
This sounds complicated and error-prone. Concretely, if Alice
|
||||||
|
receives Bob's "Member-added: Doris" message, then Alice
|
||||||
|
broadcasting the correction message with "Member-added: Carol"
|
||||||
|
would reach all four members, healing group consistency in one step.
|
||||||
|
If Bob meanwhile receives Alice's "Member-Added: Carol" message,
|
||||||
|
Bob would broadcast a correction message to all four members as well.
|
||||||
|
(Imagine a situation where Alice/Bob added Carol/Doris
|
||||||
|
while both being in an offline or bad-connection situation).
|
||||||
|
|
||||||
|
|
||||||
|
solution2: repeat member-added/removed messages
|
||||||
|
---------------------------------------------------
|
||||||
|
|
||||||
|
Introduce a new Chat-Group-Member-Changed header and deprecate Chat-Group-Member-Added/Removed
|
||||||
|
but keep sending out the old headers until the new protocol is sufficiently deployed.
|
||||||
|
|
||||||
|
The new Chat-Group-Member-Changed header contains a Time-to-Live number (TTL)
|
||||||
|
which controls repetition of the signed "add/del e-mail address" payload.
|
||||||
|
|
||||||
|
Example::
|
||||||
|
|
||||||
|
Chat-Group-Member-Changed: TTL add "somedisplayname" someone@example.org
|
||||||
|
owEBYQGe/pANAwACAY47A6J5t3LWAcsxYgBeTQypYWRkICJzb21lZGlzcGxheW5h
|
||||||
|
bWUiIHNvbWVvbmVAZXhhbXBsZS5vcmcgCokBHAQAAQIABgUCXk0MqQAKCRCOOwOi
|
||||||
|
ebdy1hfRB/wJ74tgFQulicthcv9n+ZsqzwOtBKMEVIHqJCzzDB/Hg/2z8ogYoZNR
|
||||||
|
iUKKrv3Y1XuFvdKyOC+wC/unXAWKFHYzY6Tv6qDp6r+amt+ad+8Z02q53h9E55IP
|
||||||
|
FUBdq2rbS8hLGjQB+mVRowYrUACrOqGgNbXMZjQfuV7fSc7y813OsCQgi3tjstup
|
||||||
|
b+uduVzxCp3PChGhcZPs3iOGCnQvSB8VAaLGMWE2d7nTo/yMQ0Jx69x5qwfXogTk
|
||||||
|
mTt5rOJyrosbtf09TMKFzGgtqBcEqHLp3+mQpZQ+WHUKAbsRa8Jc9DOUOSKJ8SNM
|
||||||
|
clKdskprY+4LY0EBwLD3SQ7dPkTITCRD
|
||||||
|
=P6GG
|
||||||
|
|
||||||
|
TTL is set to "2" on an initial Chat-Group-Member-Changed add/del message.
|
||||||
|
Receivers will apply the add/del change to the group-membership,
|
||||||
|
decrease the TTL by 1, and if TTL>0 re-sent the header.
|
||||||
|
|
||||||
|
The "add|del e-mail address" payload is pgp-signed and repeated verbatim.
|
||||||
|
This allows to propagate, in a cryptographically secured way,
|
||||||
|
who added a member. This is particularly important for allowing
|
||||||
|
to show in verified groups who added a member (planned).
|
||||||
|
|
||||||
|
Disadvantage to solution 1:
|
||||||
|
|
||||||
|
- requires to specify encoding and precise rules for what/how is signed.
|
||||||
|
|
||||||
|
- causes O(N^2) extra messages
|
||||||
|
|
||||||
|
- Not easily extendable for other things (without introducing a new
|
||||||
|
header / encoding)
|
||||||
|
|
||||||
|
|
||||||
@@ -6,28 +6,21 @@
|
|||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate deltachat;
|
extern crate deltachat;
|
||||||
#[macro_use]
|
|
||||||
extern crate failure;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate lazy_static;
|
|
||||||
#[macro_use]
|
|
||||||
extern crate rusqlite;
|
|
||||||
|
|
||||||
use std::borrow::Cow::{self, Borrowed, Owned};
|
use std::borrow::Cow::{self, Borrowed, Owned};
|
||||||
use std::ptr;
|
use std::io::{self, Write};
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::process::Command;
|
||||||
use std::sync::{Arc, Mutex, RwLock};
|
|
||||||
|
|
||||||
|
use ansi_term::Color;
|
||||||
|
use anyhow::{bail, Error};
|
||||||
|
use async_std::path::Path;
|
||||||
|
use deltachat::chat::ChatId;
|
||||||
use deltachat::config;
|
use deltachat::config;
|
||||||
use deltachat::configure::*;
|
|
||||||
use deltachat::constants::*;
|
|
||||||
use deltachat::context::*;
|
use deltachat::context::*;
|
||||||
use deltachat::dc_securejoin::*;
|
|
||||||
use deltachat::dc_tools::*;
|
|
||||||
use deltachat::job::*;
|
|
||||||
use deltachat::oauth2::*;
|
use deltachat::oauth2::*;
|
||||||
use deltachat::types::*;
|
use deltachat::securejoin::*;
|
||||||
use deltachat::x::*;
|
use deltachat::Event;
|
||||||
|
use log::{error, info, warn};
|
||||||
use rustyline::completion::{Completer, FilenameCompleter, Pair};
|
use rustyline::completion::{Completer, FilenameCompleter, Pair};
|
||||||
use rustyline::config::OutputStreamType;
|
use rustyline::config::OutputStreamType;
|
||||||
use rustyline::error::ReadlineError;
|
use rustyline::error::ReadlineError;
|
||||||
@@ -40,201 +33,81 @@ use rustyline::{
|
|||||||
mod cmdline;
|
mod cmdline;
|
||||||
use self::cmdline::*;
|
use self::cmdline::*;
|
||||||
|
|
||||||
// Event Handler
|
/// Event Handler
|
||||||
|
fn receive_event(event: Event) {
|
||||||
unsafe extern "C" fn receive_event(
|
let yellow = Color::Yellow.normal();
|
||||||
_context: &Context,
|
|
||||||
event: Event,
|
|
||||||
data1: uintptr_t,
|
|
||||||
data2: uintptr_t,
|
|
||||||
) -> uintptr_t {
|
|
||||||
match event {
|
match event {
|
||||||
Event::GET_STRING => {}
|
Event::Info(msg) => {
|
||||||
Event::INFO => {
|
|
||||||
/* do not show the event as this would fill the screen */
|
/* do not show the event as this would fill the screen */
|
||||||
println!("{}", to_string(data2 as *const _),);
|
info!("{}", msg);
|
||||||
}
|
}
|
||||||
Event::SMTP_CONNECTED => {
|
Event::SmtpConnected(msg) => {
|
||||||
println!("[DC_EVENT_SMTP_CONNECTED] {}", to_string(data2 as *const _));
|
info!("[SMTP_CONNECTED] {}", msg);
|
||||||
}
|
}
|
||||||
Event::IMAP_CONNECTED => {
|
Event::ImapConnected(msg) => {
|
||||||
println!("[DC_EVENT_IMAP_CONNECTED] {}", to_string(data2 as *const _),);
|
info!("[IMAP_CONNECTED] {}", msg);
|
||||||
}
|
}
|
||||||
Event::SMTP_MESSAGE_SENT => {
|
Event::SmtpMessageSent(msg) => {
|
||||||
println!(
|
info!("[SMTP_MESSAGE_SENT] {}", msg);
|
||||||
"[DC_EVENT_SMTP_MESSAGE_SENT] {}",
|
}
|
||||||
to_string(data2 as *const _),
|
Event::Warning(msg) => {
|
||||||
|
warn!("{}", msg);
|
||||||
|
}
|
||||||
|
Event::Error(msg) => {
|
||||||
|
error!("{}", msg);
|
||||||
|
}
|
||||||
|
Event::ErrorNetwork(msg) => {
|
||||||
|
error!("[NETWORK] msg={}", msg);
|
||||||
|
}
|
||||||
|
Event::ErrorSelfNotInGroup(msg) => {
|
||||||
|
error!("[SELF_NOT_IN_GROUP] {}", msg);
|
||||||
|
}
|
||||||
|
Event::MsgsChanged { chat_id, msg_id } => {
|
||||||
|
info!(
|
||||||
|
"{}",
|
||||||
|
yellow.paint(format!(
|
||||||
|
"Received MSGS_CHANGED(chat_id={}, msg_id={})",
|
||||||
|
chat_id, msg_id,
|
||||||
|
))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Event::WARNING => {
|
Event::ContactsChanged(_) => {
|
||||||
println!("[Warning] {}", to_string(data2 as *const _),);
|
info!("{}", yellow.paint("Received CONTACTS_CHANGED()"));
|
||||||
}
|
}
|
||||||
Event::ERROR => {
|
Event::LocationChanged(contact) => {
|
||||||
println!(
|
info!(
|
||||||
"\x1b[31m[DC_EVENT_ERROR] {}\x1b[0m",
|
"{}",
|
||||||
to_string(data2 as *const _),
|
yellow.paint(format!("Received LOCATION_CHANGED(contact={:?})", contact))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Event::ERROR_NETWORK => {
|
Event::ConfigureProgress(progress) => {
|
||||||
println!(
|
info!(
|
||||||
"\x1b[31m[DC_EVENT_ERROR_NETWORK] first={}, msg={}\x1b[0m",
|
"{}",
|
||||||
data1 as usize,
|
yellow.paint(format!("Received CONFIGURE_PROGRESS({} ‰)", progress))
|
||||||
to_string(data2 as *const _),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Event::ERROR_SELF_NOT_IN_GROUP => {
|
Event::ImexProgress(progress) => {
|
||||||
println!(
|
info!(
|
||||||
"\x1b[31m[DC_EVENT_ERROR_SELF_NOT_IN_GROUP] {}\x1b[0m",
|
"{}",
|
||||||
to_string(data2 as *const _),
|
yellow.paint(format!("Received IMEX_PROGRESS({} ‰)", progress))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Event::MSGS_CHANGED => {
|
Event::ImexFileWritten(file) => {
|
||||||
print!(
|
info!(
|
||||||
"\x1b[33m{{Received DC_EVENT_MSGS_CHANGED({}, {})}}\n\x1b[0m",
|
"{}",
|
||||||
data1 as usize, data2 as usize,
|
yellow.paint(format!("Received IMEX_FILE_WRITTEN({})", file.display()))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Event::CONTACTS_CHANGED => {
|
Event::ChatModified(chat) => {
|
||||||
print!("\x1b[33m{{Received DC_EVENT_CONTACTS_CHANGED()}}\n\x1b[0m");
|
info!(
|
||||||
}
|
"{}",
|
||||||
Event::LOCATION_CHANGED => {
|
yellow.paint(format!("Received CHAT_MODIFIED({})", chat))
|
||||||
print!(
|
|
||||||
"\x1b[33m{{Received DC_EVENT_LOCATION_CHANGED(contact={})}}\n\x1b[0m",
|
|
||||||
data1 as usize,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Event::CONFIGURE_PROGRESS => {
|
|
||||||
print!(
|
|
||||||
"\x1b[33m{{Received DC_EVENT_CONFIGURE_PROGRESS({} ‰)}}\n\x1b[0m",
|
|
||||||
data1 as usize,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Event::IMEX_PROGRESS => {
|
|
||||||
print!(
|
|
||||||
"\x1b[33m{{Received DC_EVENT_IMEX_PROGRESS({} ‰)}}\n\x1b[0m",
|
|
||||||
data1 as usize,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Event::IMEX_FILE_WRITTEN => {
|
|
||||||
print!(
|
|
||||||
"\x1b[33m{{Received DC_EVENT_IMEX_FILE_WRITTEN({})}}\n\x1b[0m",
|
|
||||||
to_string(data1 as *const _)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Event::CHAT_MODIFIED => {
|
|
||||||
print!(
|
|
||||||
"\x1b[33m{{Received DC_EVENT_CHAT_MODIFIED({})}}\n\x1b[0m",
|
|
||||||
data1 as usize,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
print!(
|
info!("Received {:?}", event);
|
||||||
"\x1b[33m{{Received {:?}({}, {})}}\n\x1b[0m",
|
|
||||||
event, data1 as usize, data2 as usize,
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
0
|
|
||||||
}
|
|
||||||
|
|
||||||
// Threads for waiting for messages and for jobs
|
|
||||||
|
|
||||||
lazy_static! {
|
|
||||||
static ref HANDLE: Arc<Mutex<Option<Handle>>> = Arc::new(Mutex::new(None));
|
|
||||||
static ref IS_RUNNING: AtomicBool = AtomicBool::new(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Handle {
|
|
||||||
handle_imap: Option<std::thread::JoinHandle<()>>,
|
|
||||||
handle_mvbox: Option<std::thread::JoinHandle<()>>,
|
|
||||||
handle_sentbox: Option<std::thread::JoinHandle<()>>,
|
|
||||||
handle_smtp: Option<std::thread::JoinHandle<()>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
macro_rules! while_running {
|
|
||||||
($code:block) => {
|
|
||||||
if IS_RUNNING.load(Ordering::Relaxed) {
|
|
||||||
$code
|
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
fn start_threads(c: Arc<RwLock<Context>>) {
|
|
||||||
if HANDLE.clone().lock().unwrap().is_some() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("Starting threads");
|
|
||||||
IS_RUNNING.store(true, Ordering::Relaxed);
|
|
||||||
|
|
||||||
let ctx = c.clone();
|
|
||||||
let handle_imap = std::thread::spawn(move || loop {
|
|
||||||
while_running!({
|
|
||||||
perform_imap_jobs(&ctx.read().unwrap());
|
|
||||||
perform_imap_fetch(&ctx.read().unwrap());
|
|
||||||
while_running!({
|
|
||||||
let context = ctx.read().unwrap();
|
|
||||||
perform_imap_idle(&context);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
let ctx = c.clone();
|
|
||||||
let handle_mvbox = std::thread::spawn(move || loop {
|
|
||||||
while_running!({
|
|
||||||
perform_mvbox_fetch(&ctx.read().unwrap());
|
|
||||||
while_running!({
|
|
||||||
perform_mvbox_idle(&ctx.read().unwrap());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
let ctx = c.clone();
|
|
||||||
let handle_sentbox = std::thread::spawn(move || loop {
|
|
||||||
while_running!({
|
|
||||||
perform_sentbox_fetch(&ctx.read().unwrap());
|
|
||||||
while_running!({
|
|
||||||
perform_sentbox_idle(&ctx.read().unwrap());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
let ctx = c;
|
|
||||||
let handle_smtp = std::thread::spawn(move || loop {
|
|
||||||
while_running!({
|
|
||||||
perform_smtp_jobs(&ctx.read().unwrap());
|
|
||||||
while_running!({
|
|
||||||
perform_smtp_idle(&ctx.read().unwrap());
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
*HANDLE.clone().lock().unwrap() = Some(Handle {
|
|
||||||
handle_imap: Some(handle_imap),
|
|
||||||
handle_mvbox: Some(handle_mvbox),
|
|
||||||
handle_sentbox: Some(handle_sentbox),
|
|
||||||
handle_smtp: Some(handle_smtp),
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
fn stop_threads(context: &Context) {
|
|
||||||
if let Some(ref mut handle) = *HANDLE.clone().lock().unwrap() {
|
|
||||||
println!("Stopping threads");
|
|
||||||
IS_RUNNING.store(false, Ordering::Relaxed);
|
|
||||||
|
|
||||||
interrupt_imap_idle(context);
|
|
||||||
interrupt_mvbox_idle(context);
|
|
||||||
interrupt_sentbox_idle(context);
|
|
||||||
interrupt_smtp_idle(context);
|
|
||||||
|
|
||||||
handle.handle_imap.take().unwrap().join().unwrap();
|
|
||||||
handle.handle_mvbox.take().unwrap().join().unwrap();
|
|
||||||
handle.handle_sentbox.take().unwrap().join().unwrap();
|
|
||||||
handle.handle_smtp.take().unwrap().join().unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// === The main loop
|
// === The main loop
|
||||||
@@ -258,7 +131,7 @@ impl Completer for DcHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const IMEX_COMMANDS: [&'static str; 12] = [
|
const IMEX_COMMANDS: [&str; 12] = [
|
||||||
"initiate-key-transfer",
|
"initiate-key-transfer",
|
||||||
"get-setupcodebegin",
|
"get-setupcodebegin",
|
||||||
"continue-key-transfer",
|
"continue-key-transfer",
|
||||||
@@ -273,10 +146,8 @@ const IMEX_COMMANDS: [&'static str; 12] = [
|
|||||||
"stop",
|
"stop",
|
||||||
];
|
];
|
||||||
|
|
||||||
const DB_COMMANDS: [&'static str; 11] = [
|
const DB_COMMANDS: [&str; 9] = [
|
||||||
"info",
|
"info",
|
||||||
"open",
|
|
||||||
"close",
|
|
||||||
"set",
|
"set",
|
||||||
"get",
|
"get",
|
||||||
"oauth2",
|
"oauth2",
|
||||||
@@ -287,7 +158,7 @@ const DB_COMMANDS: [&'static str; 11] = [
|
|||||||
"housekeeping",
|
"housekeeping",
|
||||||
];
|
];
|
||||||
|
|
||||||
const CHAT_COMMANDS: [&'static str; 24] = [
|
const CHAT_COMMANDS: [&str; 26] = [
|
||||||
"listchats",
|
"listchats",
|
||||||
"listarchived",
|
"listarchived",
|
||||||
"chat",
|
"chat",
|
||||||
@@ -311,9 +182,11 @@ const CHAT_COMMANDS: [&'static str; 24] = [
|
|||||||
"listmedia",
|
"listmedia",
|
||||||
"archive",
|
"archive",
|
||||||
"unarchive",
|
"unarchive",
|
||||||
|
"pin",
|
||||||
|
"unpin",
|
||||||
"delchat",
|
"delchat",
|
||||||
];
|
];
|
||||||
const MESSAGE_COMMANDS: [&'static str; 8] = [
|
const MESSAGE_COMMANDS: [&str; 8] = [
|
||||||
"listmsgs",
|
"listmsgs",
|
||||||
"msginfo",
|
"msginfo",
|
||||||
"listfresh",
|
"listfresh",
|
||||||
@@ -323,7 +196,7 @@ const MESSAGE_COMMANDS: [&'static str; 8] = [
|
|||||||
"unstar",
|
"unstar",
|
||||||
"delmsg",
|
"delmsg",
|
||||||
];
|
];
|
||||||
const CONTACT_COMMANDS: [&'static str; 6] = [
|
const CONTACT_COMMANDS: [&str; 6] = [
|
||||||
"listcontacts",
|
"listcontacts",
|
||||||
"listverified",
|
"listverified",
|
||||||
"addcontact",
|
"addcontact",
|
||||||
@@ -331,8 +204,17 @@ const CONTACT_COMMANDS: [&'static str; 6] = [
|
|||||||
"delcontact",
|
"delcontact",
|
||||||
"cleanupcontacts",
|
"cleanupcontacts",
|
||||||
];
|
];
|
||||||
const MISC_COMMANDS: [&'static str; 9] = [
|
const MISC_COMMANDS: [&str; 10] = [
|
||||||
"getqr", "getbadqr", "checkqr", "event", "fileinfo", "clear", "exit", "quit", "help",
|
"getqr",
|
||||||
|
"getbadqr",
|
||||||
|
"checkqr",
|
||||||
|
"event",
|
||||||
|
"fileinfo",
|
||||||
|
"clear",
|
||||||
|
"exit",
|
||||||
|
"quit",
|
||||||
|
"help",
|
||||||
|
"estimatedeletion",
|
||||||
];
|
];
|
||||||
|
|
||||||
impl Hinter for DcHelper {
|
impl Hinter for DcHelper {
|
||||||
@@ -357,8 +239,8 @@ impl Hinter for DcHelper {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static COLORED_PROMPT: &'static str = "\x1b[1;32m> \x1b[0m";
|
static COLORED_PROMPT: &str = "\x1b[1;32m> \x1b[0m";
|
||||||
static PROMPT: &'static str = "> ";
|
static PROMPT: &str = "> ";
|
||||||
|
|
||||||
impl Highlighter for DcHelper {
|
impl Highlighter for DcHelper {
|
||||||
fn highlight_prompt<'p>(&self, prompt: &'p str) -> Cow<'p, str> {
|
fn highlight_prompt<'p>(&self, prompt: &'p str) -> Cow<'p, str> {
|
||||||
@@ -384,29 +266,31 @@ impl Highlighter for DcHelper {
|
|||||||
|
|
||||||
impl Helper for DcHelper {}
|
impl Helper for DcHelper {}
|
||||||
|
|
||||||
fn main_0(args: Vec<String>) -> Result<(), failure::Error> {
|
async fn start(args: Vec<String>) -> Result<(), Error> {
|
||||||
let mut context = dc_context_new(Some(receive_event), ptr::null_mut(), Some("CLI".into()));
|
if args.len() < 2 {
|
||||||
|
|
||||||
unsafe { dc_cmdline_skip_auth() };
|
|
||||||
|
|
||||||
if args.len() == 2 {
|
|
||||||
if unsafe { !dc_open(&mut context, &args[1], None) } {
|
|
||||||
println!("Error: Cannot open {}.", args[0],);
|
|
||||||
}
|
|
||||||
} else if args.len() != 1 {
|
|
||||||
println!("Error: Bad arguments, expected [db-name].");
|
println!("Error: Bad arguments, expected [db-name].");
|
||||||
|
bail!("No db-name specified");
|
||||||
}
|
}
|
||||||
|
let context = Context::new("CLI".into(), Path::new(&args[1]).to_path_buf()).await?;
|
||||||
|
|
||||||
|
let events = context.get_event_emitter();
|
||||||
|
async_std::task::spawn(async move {
|
||||||
|
while let Some(event) = events.recv().await {
|
||||||
|
receive_event(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
println!("Delta Chat Core is awaiting your commands.");
|
println!("Delta Chat Core is awaiting your commands.");
|
||||||
|
|
||||||
let ctx = Arc::new(RwLock::new(context));
|
|
||||||
|
|
||||||
let config = Config::builder()
|
let config = Config::builder()
|
||||||
.history_ignore_space(true)
|
.history_ignore_space(true)
|
||||||
.completion_type(CompletionType::List)
|
.completion_type(CompletionType::List)
|
||||||
.edit_mode(EditMode::Emacs)
|
.edit_mode(EditMode::Emacs)
|
||||||
.output_stream(OutputStreamType::Stdout)
|
.output_stream(OutputStreamType::Stdout)
|
||||||
.build();
|
.build();
|
||||||
|
let mut selected_chat = ChatId::default();
|
||||||
|
let (reader_s, reader_r) = async_std::sync::channel(100);
|
||||||
|
let input_loop = async_std::task::spawn_blocking(move || {
|
||||||
let h = DcHelper {
|
let h = DcHelper {
|
||||||
completer: FilenameCompleter::new(),
|
completer: FilenameCompleter::new(),
|
||||||
highlighter: MatchingBracketHighlighter::new(),
|
highlighter: MatchingBracketHighlighter::new(),
|
||||||
@@ -423,32 +307,40 @@ fn main_0(args: Vec<String>) -> Result<(), failure::Error> {
|
|||||||
loop {
|
loop {
|
||||||
let p = "> ";
|
let p = "> ";
|
||||||
let readline = rl.readline(&p);
|
let readline = rl.readline(&p);
|
||||||
|
|
||||||
match readline {
|
match readline {
|
||||||
Ok(line) => {
|
Ok(line) => {
|
||||||
// TODO: ignore "set mail_pw"
|
// TODO: ignore "set mail_pw"
|
||||||
rl.add_history_entry(line.as_str());
|
rl.add_history_entry(line.as_str());
|
||||||
let ctx = ctx.clone();
|
async_std::task::block_on(reader_s.send(line));
|
||||||
match unsafe { handle_cmd(line.trim(), ctx) } {
|
}
|
||||||
|
Err(ReadlineError::Interrupted) | Err(ReadlineError::Eof) => {
|
||||||
|
println!("Exiting...");
|
||||||
|
drop(reader_s);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
println!("Error: {}", err);
|
||||||
|
drop(reader_s);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rl.save_history(".dc-history.txt")?;
|
||||||
|
println!("history saved");
|
||||||
|
Ok::<_, Error>(())
|
||||||
|
});
|
||||||
|
|
||||||
|
while let Ok(line) = reader_r.recv().await {
|
||||||
|
match handle_cmd(line.trim(), context.clone(), &mut selected_chat).await {
|
||||||
Ok(ExitResult::Continue) => {}
|
Ok(ExitResult::Continue) => {}
|
||||||
Ok(ExitResult::Exit) => break,
|
Ok(ExitResult::Exit) => break,
|
||||||
Err(err) => println!("Error: {}", err),
|
Err(err) => println!("Error: {}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(ReadlineError::Interrupted) | Err(ReadlineError::Eof) => {
|
context.stop_io().await;
|
||||||
println!("Exiting...");
|
input_loop.await?;
|
||||||
break;
|
|
||||||
}
|
|
||||||
Err(err) => {
|
|
||||||
println!("Error: {}", err);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
rl.save_history(".dc-history.txt")?;
|
|
||||||
println!("history saved");
|
|
||||||
{
|
|
||||||
stop_threads(&ctx.read().unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -459,48 +351,29 @@ enum ExitResult {
|
|||||||
Exit,
|
Exit,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn handle_cmd(line: &str, ctx: Arc<RwLock<Context>>) -> Result<ExitResult, failure::Error> {
|
async fn handle_cmd(
|
||||||
|
line: &str,
|
||||||
|
ctx: Context,
|
||||||
|
selected_chat: &mut ChatId,
|
||||||
|
) -> Result<ExitResult, Error> {
|
||||||
let mut args = line.splitn(2, ' ');
|
let mut args = line.splitn(2, ' ');
|
||||||
let arg0 = args.next().unwrap_or_default();
|
let arg0 = args.next().unwrap_or_default();
|
||||||
let arg1 = args.next().unwrap_or_default();
|
let arg1 = args.next().unwrap_or_default();
|
||||||
let arg1_c = if arg1.is_empty() {
|
|
||||||
std::ptr::null()
|
|
||||||
} else {
|
|
||||||
arg1.strdup()
|
|
||||||
};
|
|
||||||
|
|
||||||
match arg0 {
|
match arg0 {
|
||||||
"connect" => {
|
"connect" => {
|
||||||
start_threads(ctx);
|
ctx.start_io().await;
|
||||||
}
|
}
|
||||||
"disconnect" => {
|
"disconnect" => {
|
||||||
stop_threads(&ctx.read().unwrap());
|
ctx.stop_io().await;
|
||||||
}
|
|
||||||
"smtp-jobs" => {
|
|
||||||
if HANDLE.clone().lock().unwrap().is_some() {
|
|
||||||
println!("smtp-jobs are already running in a thread.",);
|
|
||||||
} else {
|
|
||||||
perform_smtp_jobs(&ctx.read().unwrap());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
"imap-jobs" => {
|
|
||||||
if HANDLE.clone().lock().unwrap().is_some() {
|
|
||||||
println!("imap-jobs are already running in a thread.");
|
|
||||||
} else {
|
|
||||||
perform_imap_jobs(&ctx.read().unwrap());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
"configure" => {
|
"configure" => {
|
||||||
start_threads(ctx.clone());
|
ctx.configure().await?;
|
||||||
configure(&ctx.read().unwrap());
|
|
||||||
}
|
}
|
||||||
"oauth2" => {
|
"oauth2" => {
|
||||||
if let Some(addr) = ctx.read().unwrap().get_config(config::Config::Addr) {
|
if let Some(addr) = ctx.get_config(config::Config::Addr).await {
|
||||||
let oauth2_url = dc_get_oauth2_url(
|
let oauth2_url =
|
||||||
&ctx.read().unwrap(),
|
dc_get_oauth2_url(&ctx, &addr, "chat.delta:/com.b44t.messenger").await;
|
||||||
&addr,
|
|
||||||
"chat.delta:/com.b44t.messenger",
|
|
||||||
);
|
|
||||||
if oauth2_url.is_none() {
|
if oauth2_url.is_none() {
|
||||||
println!("OAuth2 not available for {}.", &addr);
|
println!("OAuth2 not available for {}.", &addr);
|
||||||
} else {
|
} else {
|
||||||
@@ -515,47 +388,42 @@ unsafe fn handle_cmd(line: &str, ctx: Arc<RwLock<Context>>) -> Result<ExitResult
|
|||||||
print!("\x1b[1;1H\x1b[2J");
|
print!("\x1b[1;1H\x1b[2J");
|
||||||
}
|
}
|
||||||
"getqr" | "getbadqr" => {
|
"getqr" | "getbadqr" => {
|
||||||
start_threads(ctx.clone());
|
ctx.start_io().await;
|
||||||
let qrstr =
|
if let Some(mut qr) =
|
||||||
dc_get_securejoin_qr(&ctx.read().unwrap(), arg1.parse().unwrap_or_default());
|
dc_get_securejoin_qr(&ctx, ChatId::new(arg1.parse().unwrap_or_default())).await
|
||||||
if !qrstr.is_null() && 0 != *qrstr.offset(0isize) as libc::c_int {
|
{
|
||||||
if arg0 == "getbadqr" && strlen(qrstr) > 40 {
|
if !qr.is_empty() {
|
||||||
let mut i: libc::c_int = 12i32;
|
if arg0 == "getbadqr" && qr.len() > 40 {
|
||||||
while i < 22i32 {
|
qr.replace_range(12..22, "0000000000")
|
||||||
*qrstr.offset(i as isize) = '0' as i32 as libc::c_char;
|
}
|
||||||
i += 1
|
println!("{}", qr);
|
||||||
|
let output = Command::new("qrencode")
|
||||||
|
.args(&["-t", "ansiutf8", qr.as_str(), "-o", "-"])
|
||||||
|
.output()
|
||||||
|
.expect("failed to execute process");
|
||||||
|
io::stdout().write_all(&output.stdout).unwrap();
|
||||||
|
io::stderr().write_all(&output.stderr).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
println!("{}", to_string(qrstr as *const _));
|
|
||||||
let syscmd = dc_mprintf(
|
|
||||||
b"qrencode -t ansiutf8 \"%s\" -o -\x00" as *const u8 as *const libc::c_char,
|
|
||||||
qrstr,
|
|
||||||
);
|
|
||||||
system(syscmd);
|
|
||||||
free(syscmd as *mut libc::c_void);
|
|
||||||
}
|
|
||||||
free(qrstr as *mut libc::c_void);
|
|
||||||
}
|
}
|
||||||
"joinqr" => {
|
"joinqr" => {
|
||||||
start_threads(ctx.clone());
|
ctx.start_io().await;
|
||||||
if !arg0.is_empty() {
|
if !arg0.is_empty() {
|
||||||
dc_join_securejoin(&ctx.read().unwrap(), arg1_c);
|
dc_join_securejoin(&ctx, arg1).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"exit" | "quit" => return Ok(ExitResult::Exit),
|
"exit" | "quit" => return Ok(ExitResult::Exit),
|
||||||
_ => dc_cmdline(&ctx.read().unwrap(), line)?,
|
_ => cmdline(ctx.clone(), line, selected_chat).await?,
|
||||||
}
|
}
|
||||||
|
|
||||||
free(arg1_c as *mut _);
|
|
||||||
|
|
||||||
Ok(ExitResult::Continue)
|
Ok(ExitResult::Continue)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn main() -> Result<(), failure::Error> {
|
fn main() -> Result<(), Error> {
|
||||||
let _ = pretty_env_logger::try_init();
|
let _ = pretty_env_logger::try_init();
|
||||||
|
|
||||||
let args: Vec<String> = std::env::args().collect();
|
let args = std::env::args().collect();
|
||||||
main_0(args)?;
|
async_std::task::block_on(async move { start(args).await })?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,135 +1,100 @@
|
|||||||
extern crate deltachat;
|
|
||||||
|
|
||||||
use std::ffi::CStr;
|
|
||||||
use std::sync::{Arc, RwLock};
|
|
||||||
use std::{thread, time};
|
|
||||||
use tempfile::tempdir;
|
use tempfile::tempdir;
|
||||||
|
|
||||||
use deltachat::chat;
|
use deltachat::chat;
|
||||||
use deltachat::chatlist::*;
|
use deltachat::chatlist::*;
|
||||||
use deltachat::config;
|
use deltachat::config;
|
||||||
use deltachat::configure::*;
|
|
||||||
use deltachat::constants::Event;
|
|
||||||
use deltachat::contact::*;
|
use deltachat::contact::*;
|
||||||
use deltachat::context::*;
|
use deltachat::context::*;
|
||||||
use deltachat::job::{
|
use deltachat::message::Message;
|
||||||
perform_imap_fetch, perform_imap_idle, perform_imap_jobs, perform_smtp_idle, perform_smtp_jobs,
|
use deltachat::Event;
|
||||||
};
|
|
||||||
|
|
||||||
extern "C" fn cb(_ctx: &Context, event: Event, data1: usize, data2: usize) -> usize {
|
|
||||||
println!("[{:?}]", event);
|
|
||||||
|
|
||||||
|
fn cb(event: Event) {
|
||||||
match event {
|
match event {
|
||||||
Event::CONFIGURE_PROGRESS => {
|
Event::ConfigureProgress(progress) => {
|
||||||
println!(" progress: {}", data1);
|
log::info!("progress: {}", progress);
|
||||||
0
|
|
||||||
}
|
}
|
||||||
Event::INFO | Event::WARNING | Event::ERROR | Event::ERROR_NETWORK => {
|
Event::Info(msg) => {
|
||||||
println!(
|
log::info!("{}", msg);
|
||||||
" {}",
|
}
|
||||||
unsafe { CStr::from_ptr(data2 as *const _) }
|
Event::Warning(msg) => {
|
||||||
.to_str()
|
log::warn!("{}", msg);
|
||||||
.unwrap()
|
}
|
||||||
);
|
Event::Error(msg) | Event::ErrorNetwork(msg) => {
|
||||||
0
|
log::error!("{}", msg);
|
||||||
|
}
|
||||||
|
event => {
|
||||||
|
log::info!("{:?}", event);
|
||||||
}
|
}
|
||||||
_ => 0,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
/// Run with `RUST_LOG=simple=info cargo run --release --example simple --features repl -- email pw`.
|
||||||
unsafe {
|
#[async_std::main]
|
||||||
let ctx = dc_context_new(Some(cb), std::ptr::null_mut(), None);
|
async fn main() {
|
||||||
let running = Arc::new(RwLock::new(true));
|
pretty_env_logger::try_init_timed().ok();
|
||||||
let info = dc_get_info(&ctx);
|
|
||||||
let info_s = CStr::from_ptr(info);
|
|
||||||
let duration = time::Duration::from_millis(4000);
|
|
||||||
println!("info: {}", info_s.to_str().unwrap());
|
|
||||||
|
|
||||||
let ctx = Arc::new(ctx);
|
|
||||||
let ctx1 = ctx.clone();
|
|
||||||
let r1 = running.clone();
|
|
||||||
let t1 = thread::spawn(move || {
|
|
||||||
while *r1.read().unwrap() {
|
|
||||||
perform_imap_jobs(&ctx1);
|
|
||||||
if *r1.read().unwrap() {
|
|
||||||
perform_imap_fetch(&ctx1);
|
|
||||||
|
|
||||||
if *r1.read().unwrap() {
|
|
||||||
perform_imap_idle(&ctx1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let ctx1 = ctx.clone();
|
|
||||||
let r1 = running.clone();
|
|
||||||
let t2 = thread::spawn(move || {
|
|
||||||
while *r1.read().unwrap() {
|
|
||||||
perform_smtp_jobs(&ctx1);
|
|
||||||
if *r1.read().unwrap() {
|
|
||||||
perform_smtp_idle(&ctx1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let dir = tempdir().unwrap();
|
let dir = tempdir().unwrap();
|
||||||
let dbfile = dir.path().join("db.sqlite");
|
let dbfile = dir.path().join("db.sqlite");
|
||||||
|
log::info!("creating database {:?}", dbfile);
|
||||||
|
let ctx = Context::new("FakeOs".into(), dbfile.into())
|
||||||
|
.await
|
||||||
|
.expect("Failed to create context");
|
||||||
|
let info = ctx.get_info().await;
|
||||||
|
log::info!("info: {:#?}", info);
|
||||||
|
|
||||||
println!("opening database {:?}", dbfile);
|
let events = ctx.get_event_emitter();
|
||||||
|
let events_spawn = async_std::task::spawn(async move {
|
||||||
|
while let Some(event) = events.recv().await {
|
||||||
|
cb(event);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
assert!(dc_open(&ctx, dbfile.to_str().unwrap(), None));
|
log::info!("configuring");
|
||||||
|
|
||||||
println!("configuring");
|
|
||||||
let args = std::env::args().collect::<Vec<String>>();
|
let args = std::env::args().collect::<Vec<String>>();
|
||||||
assert_eq!(args.len(), 2, "missing password");
|
assert_eq!(args.len(), 3, "requires email password");
|
||||||
let pw = args[1].clone();
|
let email = args[1].clone();
|
||||||
ctx.set_config(config::Config::Addr, Some("d@testrun.org"))
|
let pw = args[2].clone();
|
||||||
|
ctx.set_config(config::Config::Addr, Some(&email))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
ctx.set_config(config::Config::MailPw, Some(&pw))
|
||||||
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
ctx.set_config(config::Config::MailPw, Some(&pw)).unwrap();
|
|
||||||
configure(&ctx);
|
|
||||||
|
|
||||||
thread::sleep(duration);
|
ctx.configure().await.unwrap();
|
||||||
|
|
||||||
println!("sending a message");
|
log::info!("------ RUN ------");
|
||||||
let contact_id =
|
ctx.start_io().await;
|
||||||
Contact::create(&ctx, "dignifiedquire", "dignifiedquire@gmail.com").unwrap();
|
log::info!("--- SENDING A MESSAGE ---");
|
||||||
let chat_id = chat::create_by_contact_id(&ctx, contact_id).unwrap();
|
|
||||||
chat::send_text_msg(&ctx, chat_id, "Hi, here is my first message!".into()).unwrap();
|
|
||||||
|
|
||||||
println!("fetching chats..");
|
let contact_id = Contact::create(&ctx, "dignifiedquire", "dignifiedquire@gmail.com")
|
||||||
let chats = Chatlist::try_load(&ctx, 0, None, None).unwrap();
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let chat_id = chat::create_by_contact_id(&ctx, contact_id).await.unwrap();
|
||||||
|
|
||||||
|
for i in 0..1 {
|
||||||
|
log::info!("sending message {}", i);
|
||||||
|
chat::send_text_msg(&ctx, chat_id, format!("Hi, here is my {}nth message!", i))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
// wait for the message to be sent out
|
||||||
|
async_std::task::sleep(std::time::Duration::from_secs(1)).await;
|
||||||
|
|
||||||
|
log::info!("fetching chats..");
|
||||||
|
let chats = Chatlist::try_load(&ctx, 0, None, None).await.unwrap();
|
||||||
|
|
||||||
for i in 0..chats.len() {
|
for i in 0..chats.len() {
|
||||||
let summary = chats.get_summary(0, None);
|
let msg = Message::load_from_db(&ctx, chats.get_msg_id(i).unwrap())
|
||||||
let text1 = summary.get_text1();
|
.await
|
||||||
let text2 = summary.get_text2();
|
.unwrap();
|
||||||
println!("chat: {} - {:?} - {:?}", i, text1, text2,);
|
log::info!("[{}] msg: {:?}", i, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
thread::sleep(duration);
|
log::info!("stopping");
|
||||||
|
ctx.stop_io().await;
|
||||||
// let msglist = dc_get_chat_msgs(&ctx, chat_id, 0, 0);
|
log::info!("closing");
|
||||||
// for i in 0..dc_array_get_cnt(msglist) {
|
drop(ctx);
|
||||||
// let msg_id = dc_array_get_id(msglist, i);
|
events_spawn.await;
|
||||||
// let msg = dc_get_msg(context, msg_id);
|
|
||||||
// let text = CStr::from_ptr(dc_msg_get_text(msg)).unwrap();
|
|
||||||
// println!("Message {}: {}\n", i + 1, text.to_str().unwrap());
|
|
||||||
// dc_msg_unref(msg);
|
|
||||||
// }
|
|
||||||
// dc_array_unref(msglist);
|
|
||||||
|
|
||||||
println!("stopping threads");
|
|
||||||
|
|
||||||
*running.clone().write().unwrap() = false;
|
|
||||||
deltachat::job::interrupt_imap_idle(&ctx);
|
|
||||||
deltachat::job::interrupt_smtp_idle(&ctx);
|
|
||||||
|
|
||||||
println!("joining");
|
|
||||||
t1.join().unwrap();
|
|
||||||
t2.join().unwrap();
|
|
||||||
|
|
||||||
println!("closing");
|
|
||||||
dc_close(&ctx);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
52
misc.c
@@ -1,52 +0,0 @@
|
|||||||
#include <stdlib.h>
|
|
||||||
#include <stdarg.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <string.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "misc.h"
|
|
||||||
|
|
||||||
|
|
||||||
static char* internal_dc_strdup(const char* s) /* strdup(NULL) is undefined, save_strdup(NULL) returns an empty string in this case */
|
|
||||||
{
|
|
||||||
char* ret = NULL;
|
|
||||||
if (s) {
|
|
||||||
if ((ret=strdup(s))==NULL) {
|
|
||||||
exit(16); /* cannot allocate (little) memory, unrecoverable error */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
if ((ret=(char*)calloc(1, 1))==NULL) {
|
|
||||||
exit(17); /* cannot allocate little memory, unrecoverable error */
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* dc_mprintf(const char* format, ...)
|
|
||||||
{
|
|
||||||
char testbuf[1];
|
|
||||||
char* buf = NULL;
|
|
||||||
int char_cnt_without_zero = 0;
|
|
||||||
|
|
||||||
va_list argp;
|
|
||||||
va_list argp_copy;
|
|
||||||
va_start(argp, format);
|
|
||||||
va_copy(argp_copy, argp);
|
|
||||||
|
|
||||||
char_cnt_without_zero = vsnprintf(testbuf, 0, format, argp);
|
|
||||||
va_end(argp);
|
|
||||||
if (char_cnt_without_zero < 0) {
|
|
||||||
va_end(argp_copy);
|
|
||||||
return internal_dc_strdup("ErrFmt");
|
|
||||||
}
|
|
||||||
|
|
||||||
buf = malloc(char_cnt_without_zero+2 /* +1 would be enough, however, protect against off-by-one-errors */);
|
|
||||||
if (buf==NULL) {
|
|
||||||
va_end(argp_copy);
|
|
||||||
return internal_dc_strdup("ErrMem");
|
|
||||||
}
|
|
||||||
|
|
||||||
vsnprintf(buf, char_cnt_without_zero+1, format, argp_copy);
|
|
||||||
va_end(argp_copy);
|
|
||||||
return buf;
|
|
||||||
}
|
|
||||||
1
misc.h
@@ -1 +0,0 @@
|
|||||||
char* dc_mprintf (const char* format, ...); /* The result must be free()'d. */
|
|
||||||
7
proptest-regressions/dc_mimeparser.txt
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Seeds for failure cases proptest has generated in the past. It is
|
||||||
|
# automatically read and these particular cases re-run before any
|
||||||
|
# novel cases are generated.
|
||||||
|
#
|
||||||
|
# It is recommended to check this file in to source control so that
|
||||||
|
# everyone who runs the test benefits from these saved cases.
|
||||||
|
cc 03cab93c6d1f3a8245f63cf84dacb307944294fe6333c1e38f078a6600659c7a # shrinks to data = "a\t0aA\ta\t0 \ta\t0 \ta a\t\ta A\tAA0a0a 0\t a\t aA \t a\t A0\t AAa\taA0\taAAaA\t0\taa0a\ta Aa Aaaa A0A\t a aA 0\t A\t0\t0\t\t\t\t\t\tA \t\t a\tA Aa aAA0A0AA0aaA A\t\t aa0\ta\t \tAa\taA\t00 AA A a\tA a aAAa \t 00\t0 \t\t a A 0\t\t\t aAA Aa \taAAAA0a A0A\t\t1\\E$\t$R\tc\t^=\t\"\tQ<Uk\t\t>A\t\t&\t}v&\tM^\'|\tW5?dn\t\t+\t\tP\te`\t\t>:Brlq--?\t$#Q\tK=zJ\tb\"9*.\"\t`\tF&T*\tBs,\tg\'*\\\t:\t?l$\t\t|A\"HR:Hk\t\\KkV\t\t{=&!^e%:|_*0wV\t[$`\t:\t$%f\t\t[!\"Y. \tP\t\th\'?\'/?%:++NfQo#@\"+?\t(\\??{\t\'\'$Dzj\t0.?{s4?&?Y=/yj]Z=\t4n\t?Ja\"\t{I\t$\t;I}_8V\t&\t?N\'\tI2/\t9.\tFT%9%`\'\tz\to7Y\t|AXP&@G12g\t\'w\t\t%??\t\"h$?F\"\"6%q\\\\{\tT\t\"]$87$}h\'\t<\t$\tc%U:mT2:<v\t#Rl!;U\t\t\"^D\tRZ(BZ{n\t%[$fgH`\t{B}:*\t\t%%*F`%W\t//B}PQ\t\tsu2\tLz<1*!p-X\tnKv&&0\thm4<n\\.\\/.w\'\t<)E1g3#ood\t`?\t\\({N?,8_?h\ty\t0%\t*$A\t\t*w-ViQUj\tTiH\t%\t%&0p\'\'\tA%r**Fo\'Z\\\tNI*ely4=I?}$.o`\t$\ts\'<\t\",:~=Nv/0O%=+<LS\t%P\'\t$r%d.\t{G{/L:\t&I&8-`cy*\"{\t/%fP9.P<\t\t\'/`\t\t`\t\t`!t:\t::\t\tW\'X^\t@.uL&a\tN\t\t\t.\t?0*\tvUK>UJ\\\tQbj%w]P=Js\t\"R\t&s^?</=%\t\'VI:\" kT`{b*<\t\tF&?Y\t\t:/\t!C\'e0`\t\t\tx-\t*\\N\\wwu.I4\tb/y\t\"P:P%\"\t\tQ][\\\t^x\t\t):\t\t&s\t$1-\t\t\tXt`0\t;\t/UeCP*\"G\t\t\':\tk@91Hf&#\t(Uzz&`p2;\t{]\t\"I_%=\\%,XD\"\'06QfCd<;$:q^\t8:\"*\"H\t\to\t&xK/\t\ty0/<}<j<|*`~::b\t=S.=}=Ki\t<Y.\'{\tf\t{Ub*H%(_4*?*\tn2\t/\'\t\t\t/,4]\tt\t<y\t\t\tWi\t\tT&\"\t\t\t\t\t=/1Wu?\t\'A\"W-P\t$?e\\\t`\t6`vD\t8`\t\tccD J\tY&jI//?_\t\\j\t_\tsiq$\t?9\tQ\t.^%&..?%Jm??A%+<\tN&*\t.g\tS$W\"\"\tMpq\t\t:&\\\thTz&<iz%/%T&\'F\t\\]&\t\t}\t\t\tXr=dtp`:+<,\t%60Y*<(&K*kJ\todO\t=<V?&\tMU/\"\t= Y!)<\tV\t9\t)\t&v8q{\t\t&pT\t3\ttB,qcq\'i$;gv%j_%M_{[\"&;\t\t\t.B;6Y\\%\t\"\tY/a\t\\`:?\t<\t?]\taNwD;\\\t%l*74%5T?QS :~yR/E*R\t\t=u\t\\\t\t.Q<;\\\t_S/{&F$^\tw_>\'h=|%\t\t:W!\\<U2\'$\tb&`\t=|=L9\t\t\t\\WZ:! }{\t ;\t;\t\t 0.*\t.%\"\'r%{<Mh_t[[}\t-\tJo\"b/AC*-=`=T\tz$2\tC\t\t/k{47\"\t\t,q%\tZ\tT3\t\tf>%\t\'?%@^tx\t7\"1Bk{b{n\t\"Pj3\tHc\t\tt\tY<\t#?\tSh\\yk/N\\\t8 7=R4*9Cw&m\t\\-\'f\t|\'#t(Etu.Hdu(E\t%&v:\'aqW~A5\t\t w.s{J%lX<\"\t\'*%m<&:/B<&\':U}$&`.{)\t\t6S\t:/$*kQ-Z\t^\'t${/tH*\'v\t3\t=\t\tDyp:B\t`I_R&4SO\t\t&-j=*.\t87&\'e*( \t\t\t\'<$\\DJ<$p?{}\'&\tv\t\\Xk<Y:Y`!$K{\tF&\tzd\t\t*i$\tj\'\t<)R*\t%?\t!.\t=\"@#~:=*\t\tXO=_T,1\"\'.%%\"`{\\:\t\"\tfkeOb/\'$I~\ta\t|&\t[\\KK\"1&Z\t<k\t\t)%\'-~\"2n\tj\tW?*<@w{g%d\ta\\\'\'I\t;:ySR%ke:4\tc\t$=\t&9P]x4\tJ=\t6C6%a\t`0\tF\tm-\tTr\t}\t\tQum\t&@\typ|w2&\t\t3`i&t\t\tT5\"\t.&b&e*/==1.\'*\\[U*\tqPL%?$-0/}~|q`\t\t}\t$\tq==o+T$\'!H\t\ti&um\"?\"%%\t/\'p\tg>?{0{J{\t\t/\t\t{zKZ&>=\t[\"1h<H%z/8,/]s\tv{7\t\t:j*H,M//\t\t\td\'.)\t"
|
||||||
8
proptest-regressions/dc_strencode.txt
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
# Seeds for failure cases proptest has generated in the past. It is
|
||||||
|
# automatically read and these particular cases re-run before any
|
||||||
|
# novel cases are generated.
|
||||||
|
#
|
||||||
|
# It is recommended to check this file in to source control so that
|
||||||
|
# everyone who runs the test benefits from these saved cases.
|
||||||
|
cc 679506fe9ac59df773f8cfa800fdab5f0a32fe49d2ab370394000a1aa5bc2a72 # shrinks to buf = "%0A"
|
||||||
|
cc e34960438edb2426904b44fb4215154e7e2880f2fd1c3183b98bfcc76fec4882 # shrinks to input = " 0"
|
||||||
9
proptest-regressions/dc_tools.txt
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
# Seeds for failure cases proptest has generated in the past. It is
|
||||||
|
# automatically read and these particular cases re-run before any
|
||||||
|
# novel cases are generated.
|
||||||
|
#
|
||||||
|
# It is recommended to check this file in to source control so that
|
||||||
|
# everyone who runs the test benefits from these saved cases.
|
||||||
|
cc c310754465ee0261807b96fa9bcc4861ff9aa286e94667524b5960c69f9b6620 # shrinks to buf = "", approx_chars = 0, do_unwrap = false
|
||||||
|
cc 5fd8d730b0a9cdf7308ce58818ca9aefc0255c9ba2a0878944fc48d43a67315b # shrinks to buf = "𑒀ὐ¢🜀\u{1e01b}A a🟠", approx_chars = 0, do_unwrap = false
|
||||||
|
cc c6a0029a54137a4b9efc9ef2ea6d9a7dd1d60d1c937bb472b66a174618ba8013 # shrinks to buf = "𐠈0Aᝮa𫝀®!ꫛa¡0A𐢧00𐹠®A 丽ⷐએ ", approx_chars = 0, do_unwrap = false
|
||||||
@@ -1,6 +1,29 @@
|
|||||||
0.600.1
|
0.900.0 (DRAFT)
|
||||||
|
---------------
|
||||||
|
|
||||||
|
- refactored internals to use plugin-approach
|
||||||
|
|
||||||
|
- introduced PerAccount and Global hooks that plugins can implement
|
||||||
|
|
||||||
|
- introduced `ac_member_added()` and `ac_member_removed()` plugin events.
|
||||||
|
|
||||||
|
- introduced two documented examples for an echo and a group-membership
|
||||||
|
tracking plugin.
|
||||||
|
|
||||||
|
0.800.0
|
||||||
|
-------
|
||||||
|
|
||||||
|
- use latest core 1.25.0
|
||||||
|
|
||||||
|
- refine tests and some internal changes to core bindings
|
||||||
|
|
||||||
|
0.700.0
|
||||||
---------
|
---------
|
||||||
|
|
||||||
|
- lots of new Python APIs
|
||||||
|
|
||||||
|
- use rust core-beta23
|
||||||
|
|
||||||
- introduce automatic versioning via setuptools_scm,
|
- introduce automatic versioning via setuptools_scm,
|
||||||
based on py-X.Y.Z tags
|
based on py-X.Y.Z tags
|
||||||
|
|
||||||
|
|||||||
@@ -3,41 +3,98 @@ deltachat python bindings
|
|||||||
=========================
|
=========================
|
||||||
|
|
||||||
This package provides bindings to the deltachat-core_ Rust -library
|
This package provides bindings to the deltachat-core_ Rust -library
|
||||||
which provides imap/smtp/crypto handling as well as chat/group/messages
|
which implements IMAP/SMTP/MIME/PGP e-mail standards and offers
|
||||||
handling to Android, Desktop and IO user interfaces.
|
a low-level Chat/Contact/Message API to user interfaces and bots.
|
||||||
|
|
||||||
Installing pre-built packages (linux-only)
|
|
||||||
==========================================
|
|
||||||
|
|
||||||
If you have a linux system you may install the ``deltachat`` binary "wheel" package
|
Installing bindings from source (Updated: 20-Jan-2020)
|
||||||
|
=========================================================
|
||||||
|
|
||||||
|
Install Rust and Cargo first. Deltachat needs a specific nightly
|
||||||
|
version, the easiest is probably to first install Rust stable from
|
||||||
|
rustup and then use this to install the correct nightly version.
|
||||||
|
|
||||||
|
Bootstrap Rust and Cargo by using rustup::
|
||||||
|
|
||||||
|
curl https://sh.rustup.rs -sSf | sh
|
||||||
|
|
||||||
|
Then GIT clone the deltachat-core-rust repo and get the actual
|
||||||
|
rust- and cargo-toolchain needed by deltachat::
|
||||||
|
|
||||||
|
git clone https://github.com/deltachat/deltachat-core-rust
|
||||||
|
cd deltachat-core-rust
|
||||||
|
rustup show
|
||||||
|
|
||||||
|
To install the Delta Chat Python bindings make sure you have Python3 installed.
|
||||||
|
E.g. on Debian-based systems `apt install python3 python3-pip
|
||||||
|
python3-venv` should give you a usable python installation.
|
||||||
|
|
||||||
|
Ensure you are in the deltachat-core-rust/python directory, create the
|
||||||
|
virtual environment and activate it in your shell::
|
||||||
|
|
||||||
|
cd python
|
||||||
|
python3 -m venv venv # or: virtualenv venv
|
||||||
|
source venv/bin/activate
|
||||||
|
|
||||||
|
You should now be able to build the python bindings using the supplied script::
|
||||||
|
|
||||||
|
./install_python_bindings.py
|
||||||
|
|
||||||
|
The installation might take a while, depending on your machine.
|
||||||
|
The bindings will be installed in release mode but with debug symbols.
|
||||||
|
The release mode is currently necessary because some tests generate RSA keys
|
||||||
|
which is prohibitively slow in non-release mode.
|
||||||
|
|
||||||
|
After successful binding installation you can install a few more
|
||||||
|
Python packages before running the tests::
|
||||||
|
|
||||||
|
python -m pip install pytest pytest-timeout pytest-rerunfailures requests
|
||||||
|
pytest -v tests
|
||||||
|
|
||||||
|
|
||||||
|
running "live" tests with temporary accounts
|
||||||
|
---------------------------------------------
|
||||||
|
|
||||||
|
If you want to run "liveconfig" functional tests you can set
|
||||||
|
``DCC_NEW_TMP_EMAIL`` to:
|
||||||
|
|
||||||
|
- a particular https-url that you can ask for from the delta
|
||||||
|
chat devs. This is implemented on the server side via
|
||||||
|
the [mailadm](https://github.com/deltachat/mailadm) command line tool.
|
||||||
|
|
||||||
|
- or the path of a file that contains two lines, each describing
|
||||||
|
via "addr=... mail_pw=..." a test account login that will
|
||||||
|
be used for the live tests.
|
||||||
|
|
||||||
|
With ``DCC_NEW_TMP_EMAIL`` set pytest invocations will use real
|
||||||
|
e-mail accounts and run through all functional "liveconfig" tests.
|
||||||
|
|
||||||
|
|
||||||
|
Installing pre-built packages (Linux-only)
|
||||||
|
========================================================
|
||||||
|
|
||||||
|
If you have a Linux system you may try to install the ``deltachat`` binary "wheel" packages
|
||||||
without any "build-from-source" steps.
|
without any "build-from-source" steps.
|
||||||
|
|
||||||
1. `Install virtualenv <https://virtualenv.pypa.io/en/stable/installation/>`_,
|
We suggest to `Install virtualenv <https://virtualenv.pypa.io/en/stable/installation/>`_,
|
||||||
then create a fresh python environment and activate it in your shell::
|
then create a fresh Python virtual environment and activate it in your shell::
|
||||||
|
|
||||||
virtualenv venv # or: python -m venv
|
virtualenv venv # or: python -m venv
|
||||||
source venv/bin/activate
|
source venv/bin/activate
|
||||||
|
|
||||||
Afterwards, invoking ``python`` or ``pip install`` will only
|
Afterwards, invoking ``python`` or ``pip install`` only
|
||||||
modify files in your ``venv`` directory and leave your system installation
|
modifies files in your ``venv`` directory and leaves
|
||||||
alone.
|
your system installation alone.
|
||||||
|
|
||||||
2. Install the wheel for linux::
|
|
||||||
|
|
||||||
pip install deltachat
|
|
||||||
|
|
||||||
Verify it worked by typing::
|
|
||||||
|
|
||||||
python -c "import deltachat"
|
|
||||||
|
|
||||||
|
|
||||||
Installing a wheel from a PR/branch
|
|
||||||
---------------------------------------
|
|
||||||
|
|
||||||
For Linux, we automatically build wheels for all github PR branches
|
For Linux, we automatically build wheels for all github PR branches
|
||||||
and push them to a python package index. To install the latest github ``master`` branch::
|
and push them to a python package index. To install the latest
|
||||||
|
github ``master`` branch::
|
||||||
|
|
||||||
pip install -i https://m.devpi.net/dc/master deltachat
|
pip install --pre -i https://m.devpi.net/dc/master deltachat
|
||||||
|
|
||||||
|
To verify it worked::
|
||||||
|
|
||||||
|
python -c "import deltachat"
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
@@ -46,65 +103,6 @@ and push them to a python package index. To install the latest github ``master``
|
|||||||
`in contact with us <https://delta.chat/en/contribute>`_.
|
`in contact with us <https://delta.chat/en/contribute>`_.
|
||||||
|
|
||||||
|
|
||||||
Installing bindings from source
|
|
||||||
===============================
|
|
||||||
|
|
||||||
If you can't use "binary" method above then you need to compile
|
|
||||||
to core deltachat library::
|
|
||||||
|
|
||||||
git clone https://github.com/deltachat/deltachat-core-rust
|
|
||||||
cd deltachat-core-rust
|
|
||||||
cd python
|
|
||||||
|
|
||||||
If you don't have one active, create and activate a python "virtualenv":
|
|
||||||
|
|
||||||
python virtualenv venv # or python -m venv
|
|
||||||
source venv/bin/activate
|
|
||||||
|
|
||||||
Afterwards ``which python`` tells you that it comes out of the "venv"
|
|
||||||
directory that contains all python install artifacts. Let's first
|
|
||||||
install test tools::
|
|
||||||
|
|
||||||
pip install pytest pytest-timeout requests
|
|
||||||
|
|
||||||
then cargo-build and install the deltachat bindings::
|
|
||||||
|
|
||||||
python install_python_bindings.py
|
|
||||||
|
|
||||||
The bindings will be installed in release mode but with debug symbols.
|
|
||||||
The release mode is neccessary because some tests generate RSA keys
|
|
||||||
which is prohibitively slow in debug mode.
|
|
||||||
|
|
||||||
After succcessul binding installation you can finally run the tests::
|
|
||||||
|
|
||||||
pytest -v tests
|
|
||||||
|
|
||||||
.. note::
|
|
||||||
|
|
||||||
Some tests are sometimes failing/hanging because of
|
|
||||||
https://github.com/deltachat/deltachat-core-rust/issues/331
|
|
||||||
and
|
|
||||||
https://github.com/deltachat/deltachat-core-rust/issues/326
|
|
||||||
|
|
||||||
|
|
||||||
running "live" tests (experimental)
|
|
||||||
-----------------------------------
|
|
||||||
|
|
||||||
If you want to run "liveconfig" functional tests you can set
|
|
||||||
``DCC_PY_LIVECONFIG`` to:
|
|
||||||
|
|
||||||
- a particular https-url that you can ask for from the delta
|
|
||||||
chat devs.
|
|
||||||
|
|
||||||
- or the path of a file that contains two lines, each describing
|
|
||||||
via "addr=... mail_pwd=..." a test account login that will
|
|
||||||
be used for the live tests.
|
|
||||||
|
|
||||||
With ``DCC_PY_LIVECONFIG`` set pytest invocations will use real
|
|
||||||
e-mail accounts and run through all functional "liveconfig" tests.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Code examples
|
Code examples
|
||||||
=============
|
=============
|
||||||
|
|
||||||
@@ -115,15 +113,11 @@ You may look at `examples <https://py.delta.chat/examples.html>`_.
|
|||||||
.. _`deltachat-core`: https://github.com/deltachat/deltachat-core-rust
|
.. _`deltachat-core`: https://github.com/deltachat/deltachat-core-rust
|
||||||
|
|
||||||
|
|
||||||
Building manylinux1 wheels
|
Building manylinux based wheels
|
||||||
==========================
|
====================================
|
||||||
|
|
||||||
.. note::
|
Building portable manylinux wheels which come with libdeltachat.so
|
||||||
|
can be done with docker-tooling.
|
||||||
This section may not fully work.
|
|
||||||
|
|
||||||
Building portable manylinux1 wheels which come with libdeltachat.so
|
|
||||||
and all it's dependencies is easy using the provided docker tooling.
|
|
||||||
|
|
||||||
using docker pull / premade images
|
using docker pull / premade images
|
||||||
------------------------------------
|
------------------------------------
|
||||||
@@ -136,9 +130,9 @@ organization::
|
|||||||
|
|
||||||
This docker image can be used to run tests and build Python wheels for all interpreters::
|
This docker image can be used to run tests and build Python wheels for all interpreters::
|
||||||
|
|
||||||
$ bash ci_scripts/ci_run.sh
|
$ docker run -e DCC_NEW_TMP_EMAIL \
|
||||||
|
--rm -it -v \$(pwd):/mnt -w /mnt \
|
||||||
This command runs tests and build-wheel scripts in a docker container.
|
deltachat/coredeps ci_scripts/run_all.sh
|
||||||
|
|
||||||
|
|
||||||
Optionally build your own docker image
|
Optionally build your own docker image
|
||||||
|
|||||||
4
python/doc/_static/custom.css
vendored
@@ -15,3 +15,7 @@ div.globaltoc {
|
|||||||
img.logo {
|
img.logo {
|
||||||
height: 120px;
|
height: 120px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
div.footer {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|||||||
1
python/doc/_templates/globaltoc.html
vendored
@@ -6,7 +6,6 @@
|
|||||||
<li><a href="{{ pathto('install') }}">install</a></li>
|
<li><a href="{{ pathto('install') }}">install</a></li>
|
||||||
<li><a href="{{ pathto('api') }}">high level API</a></li>
|
<li><a href="{{ pathto('api') }}">high level API</a></li>
|
||||||
<li><a href="{{ pathto('lapi') }}">low level API</a></li>
|
<li><a href="{{ pathto('lapi') }}">low level API</a></li>
|
||||||
<li><a href="{{ pathto('capi') }}">C deltachat.h</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
<b>external links:</b>
|
<b>external links:</b>
|
||||||
<ul>
|
<ul>
|
||||||
|
|||||||
@@ -2,14 +2,10 @@
|
|||||||
high level API reference
|
high level API reference
|
||||||
========================
|
========================
|
||||||
|
|
||||||
.. note::
|
|
||||||
|
|
||||||
This API is work in progress and may change in versions prior to 1.0.
|
|
||||||
|
|
||||||
- :class:`deltachat.account.Account` (your main entry point, creates the
|
- :class:`deltachat.account.Account` (your main entry point, creates the
|
||||||
other classes)
|
other classes)
|
||||||
- :class:`deltachat.chatting.Contact`
|
- :class:`deltachat.contact.Contact`
|
||||||
- :class:`deltachat.chatting.Chat`
|
- :class:`deltachat.chat.Chat`
|
||||||
- :class:`deltachat.message.Message`
|
- :class:`deltachat.message.Message`
|
||||||
|
|
||||||
Account
|
Account
|
||||||
@@ -22,13 +18,13 @@ Account
|
|||||||
Contact
|
Contact
|
||||||
-------
|
-------
|
||||||
|
|
||||||
.. autoclass:: deltachat.chatting.Contact
|
.. autoclass:: deltachat.contact.Contact
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
Chat
|
Chat
|
||||||
----
|
----
|
||||||
|
|
||||||
.. autoclass:: deltachat.chatting.Chat
|
.. autoclass:: deltachat.chat.Chat
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
Message
|
Message
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
|
|
||||||
C deltachat interface
|
|
||||||
=====================
|
|
||||||
|
|
||||||
See :doc:`lapi` for accessing many of the below functions
|
|
||||||
through the ``deltachat.capi.lib`` namespace.
|
|
||||||
|
|
||||||
@@ -55,7 +55,7 @@ master_doc = 'index'
|
|||||||
|
|
||||||
# General information about the project.
|
# General information about the project.
|
||||||
project = u'deltachat'
|
project = u'deltachat'
|
||||||
copyright = u'2018, holger krekel and contributors'
|
copyright = u'2020, holger krekel and contributors'
|
||||||
|
|
||||||
|
|
||||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||||
|
|||||||
@@ -1,37 +1,60 @@
|
|||||||
|
|
||||||
|
|
||||||
examples
|
examples
|
||||||
========
|
========
|
||||||
|
|
||||||
|
|
||||||
Playing around on the commandline
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Once you have :doc:`installed deltachat bindings <install>`
|
Once you have :doc:`installed deltachat bindings <install>`
|
||||||
you can start playing from the python interpreter commandline.
|
you need email/password credentials for an IMAP/SMTP account.
|
||||||
For example you can type ``python`` and then::
|
Delta Chat developers and the CI system use a special URL to create
|
||||||
|
temporary e-mail accounts on [testrun.org](https://testrun.org) for testing.
|
||||||
|
|
||||||
# instantiate and configure deltachat account
|
Receiving a Chat message from the command line
|
||||||
import deltachat
|
----------------------------------------------
|
||||||
ac = deltachat.Account("/tmp/db")
|
|
||||||
|
|
||||||
# start configuration activity and smtp/imap threads
|
Here is a simple bot that:
|
||||||
ac.start_threads()
|
|
||||||
ac.configure(addr="test2@hq5.merlinux.eu", mail_pw="********")
|
|
||||||
|
|
||||||
# create a contact and send a message
|
- receives a message and sends back ("echoes") a message
|
||||||
contact = ac.create_contact("someother@email.address")
|
|
||||||
chat = ac.create_chat_by_contact(contact)
|
|
||||||
chat.send_text("hi from the python interpreter command line")
|
|
||||||
|
|
||||||
Checkout our :doc:`api` for the various high-level things you can do
|
- terminates the bot if the message `/quit` is sent
|
||||||
to send/receive messages, create contacts and chats.
|
|
||||||
|
|
||||||
|
.. include:: ../examples/echo_and_quit.py
|
||||||
|
:literal:
|
||||||
|
|
||||||
Looking at a real example
|
With this file in your working directory you can run the bot
|
||||||
|
by specifying a database path, an e-mail address and password of
|
||||||
|
a SMTP-IMAP account::
|
||||||
|
|
||||||
|
$ cd examples
|
||||||
|
$ python echo_and_quit.py /tmp/db --email ADDRESS --password PASSWORD
|
||||||
|
|
||||||
|
While this process is running you can start sending chat messages
|
||||||
|
to `ADDRESS`.
|
||||||
|
|
||||||
|
Track member additions and removals in a group
|
||||||
|
----------------------------------------------
|
||||||
|
|
||||||
|
Here is a simple bot that:
|
||||||
|
|
||||||
|
- echoes messages sent to it
|
||||||
|
|
||||||
|
- tracks if configuration completed
|
||||||
|
|
||||||
|
- tracks member additions and removals for all chat groups
|
||||||
|
|
||||||
|
.. include:: ../examples/group_tracking.py
|
||||||
|
:literal:
|
||||||
|
|
||||||
|
With this file in your working directory you can run the bot
|
||||||
|
by specifying a database path, an e-mail address and password of
|
||||||
|
a SMTP-IMAP account::
|
||||||
|
|
||||||
|
python group_tracking.py --email ADDRESS --password PASSWORD /tmp/db
|
||||||
|
|
||||||
|
When this process is running you can start sending chat messages
|
||||||
|
to `ADDRESS`.
|
||||||
|
|
||||||
|
Writing bots for real
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
The `deltabot repository <https://github.com/deltachat/deltabot#deltachat-example-bot>`_
|
The `deltabot repository <https://github.com/deltachat/deltabot#deltachat-example-bot>`_
|
||||||
contains a real-life example of Python bindings usage.
|
contains a little framework for writing deltachat bots in Python.
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,15 +1,15 @@
|
|||||||
deltachat python bindings
|
deltachat python bindings
|
||||||
=========================
|
=========================
|
||||||
|
|
||||||
The ``deltachat`` Python package provides two bindings for the core Rust-library
|
The ``deltachat`` Python package provides two layers of bindings for the
|
||||||
of the https://delta.chat messaging ecosystem:
|
core Rust-library of the https://delta.chat messaging ecosystem:
|
||||||
|
|
||||||
- :doc:`api` is a high level interface to deltachat-core which aims
|
- :doc:`api` is a high level interface to deltachat-core.
|
||||||
to be memory safe and thoroughly tested through continous tox/pytest runs.
|
|
||||||
|
|
||||||
- :doc:`capi` is a lowlevel CFFI-binding to the previous
|
- :doc:`plugins` is a brief introduction into implementing plugin hooks.
|
||||||
`deltachat-core C-API <https://c.delta.chat>`_ (so far the Rust library
|
|
||||||
replicates exactly the same C-level API).
|
- :doc:`lapi` is a lowlevel CFFI-binding to the `Rust Core
|
||||||
|
<https://github.com/deltachat/deltachat-core-rust>`_.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -28,8 +28,8 @@ getting started
|
|||||||
links
|
links
|
||||||
changelog
|
changelog
|
||||||
api
|
api
|
||||||
capi
|
|
||||||
lapi
|
lapi
|
||||||
|
plugins
|
||||||
|
|
||||||
..
|
..
|
||||||
Indices and tables
|
Indices and tables
|
||||||
|
|||||||
@@ -2,7 +2,13 @@
|
|||||||
low level API reference
|
low level API reference
|
||||||
===================================
|
===================================
|
||||||
|
|
||||||
for full C-docs, defines and function checkout :doc:`capi`
|
for full doxygen-generated C-docs, defines and functions please checkout
|
||||||
|
|
||||||
|
https://c.delta.chat
|
||||||
|
|
||||||
|
|
||||||
|
Python low-level capi calls
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
|
||||||
.. automodule:: deltachat.capi.lib
|
.. automodule:: deltachat.capi.lib
|
||||||
|
|||||||
38
python/doc/plugins.rst
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
|
||||||
|
Implementing Plugin Hooks
|
||||||
|
==========================
|
||||||
|
|
||||||
|
The Delta Chat Python bindings use `pluggy <https://pluggy.readthedocs.io>`_
|
||||||
|
for managing global and per-account plugin registration, and performing
|
||||||
|
hook calls. There are two kinds of plugins:
|
||||||
|
|
||||||
|
- Global plugins that are active for all accounts; they can implement
|
||||||
|
hooks at account-creation and account-shutdown time.
|
||||||
|
|
||||||
|
- Account plugins that are only active during the lifetime of a
|
||||||
|
single Account instance.
|
||||||
|
|
||||||
|
|
||||||
|
Registering a plugin
|
||||||
|
--------------------
|
||||||
|
|
||||||
|
.. autofunction:: deltachat.register_global_plugin
|
||||||
|
:noindex:
|
||||||
|
|
||||||
|
.. automethod:: deltachat.account.Account.add_account_plugin
|
||||||
|
:noindex:
|
||||||
|
|
||||||
|
|
||||||
|
Per-Account Hook specifications
|
||||||
|
-------------------------------
|
||||||
|
|
||||||
|
.. autoclass:: deltachat.hookspec.PerAccount
|
||||||
|
:members:
|
||||||
|
|
||||||
|
|
||||||
|
Global Hook specifications
|
||||||
|
--------------------------
|
||||||
|
|
||||||
|
.. autoclass:: deltachat.hookspec.Global
|
||||||
|
:members:
|
||||||
|
|
||||||
33
python/examples/echo_and_quit.py
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
|
||||||
|
# content of echo_and_quit.py
|
||||||
|
|
||||||
|
from deltachat import account_hookimpl, run_cmdline
|
||||||
|
|
||||||
|
|
||||||
|
class EchoPlugin:
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_incoming_message(self, message):
|
||||||
|
print("process_incoming message", message)
|
||||||
|
if message.text.strip() == "/quit":
|
||||||
|
message.account.shutdown()
|
||||||
|
else:
|
||||||
|
# unconditionally accept the chat
|
||||||
|
message.create_chat()
|
||||||
|
addr = message.get_sender_contact().addr
|
||||||
|
if message.is_system_message():
|
||||||
|
message.chat.send_text("echoing system message from {}:\n{}".format(addr, message))
|
||||||
|
else:
|
||||||
|
text = message.text
|
||||||
|
message.chat.send_text("echoing from {}:\n{}".format(addr, text))
|
||||||
|
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_message_delivered(self, message):
|
||||||
|
print("ac_message_delivered", message)
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv=None):
|
||||||
|
run_cmdline(argv=argv, account_plugins=[EchoPlugin()])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
52
python/examples/group_tracking.py
Normal file
@@ -0,0 +1,52 @@
|
|||||||
|
|
||||||
|
# content of group_tracking.py
|
||||||
|
|
||||||
|
from deltachat import account_hookimpl, run_cmdline
|
||||||
|
|
||||||
|
|
||||||
|
class GroupTrackingPlugin:
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_incoming_message(self, message):
|
||||||
|
print("process_incoming message", message)
|
||||||
|
if message.text.strip() == "/quit":
|
||||||
|
message.account.shutdown()
|
||||||
|
else:
|
||||||
|
# unconditionally accept the chat
|
||||||
|
message.create_chat()
|
||||||
|
addr = message.get_sender_contact().addr
|
||||||
|
text = message.text
|
||||||
|
message.chat.send_text("echoing from {}:\n{}".format(addr, text))
|
||||||
|
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_outgoing_message(self, message):
|
||||||
|
print("ac_outgoing_message:", message)
|
||||||
|
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_configure_completed(self, success):
|
||||||
|
print("ac_configure_completed:", success)
|
||||||
|
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_chat_modified(self, chat):
|
||||||
|
print("ac_chat_modified:", chat.id, chat.get_name())
|
||||||
|
for member in chat.get_contacts():
|
||||||
|
print("chat member: {}".format(member.addr))
|
||||||
|
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_member_added(self, chat, contact, message):
|
||||||
|
print("ac_member_added {} to chat {} from {}".format(
|
||||||
|
contact.addr, chat.id, message.get_sender_contact().addr))
|
||||||
|
for member in chat.get_contacts():
|
||||||
|
print("chat member: {}".format(member.addr))
|
||||||
|
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_member_removed(self, chat, contact, message):
|
||||||
|
print("ac_member_removed {} from chat {} by {}".format(
|
||||||
|
contact.addr, chat.id, message.get_sender_contact().addr))
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv=None):
|
||||||
|
run_cmdline(argv=argv, account_plugins=[GroupTrackingPlugin()])
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
79
python/examples/test_examples.py
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
|
||||||
|
import pytest
|
||||||
|
import py
|
||||||
|
import echo_and_quit
|
||||||
|
import group_tracking
|
||||||
|
from deltachat.events import FFIEventLogger
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope='session')
|
||||||
|
def datadir():
|
||||||
|
"""The py.path.local object of the test-data/ directory."""
|
||||||
|
for path in reversed(py.path.local(__file__).parts()):
|
||||||
|
datadir = path.join('test-data')
|
||||||
|
if datadir.isdir():
|
||||||
|
return datadir
|
||||||
|
else:
|
||||||
|
pytest.skip('test-data directory not found')
|
||||||
|
|
||||||
|
|
||||||
|
def test_echo_quit_plugin(acfactory, lp):
|
||||||
|
lp.sec("creating one echo_and_quit bot")
|
||||||
|
botproc = acfactory.run_bot_process(echo_and_quit)
|
||||||
|
|
||||||
|
lp.sec("creating a temp account to contact the bot")
|
||||||
|
ac1 = acfactory.get_one_online_account()
|
||||||
|
|
||||||
|
lp.sec("sending a message to the bot")
|
||||||
|
bot_contact = ac1.create_contact(botproc.addr)
|
||||||
|
bot_chat = bot_contact.create_chat()
|
||||||
|
bot_chat.send_text("hello")
|
||||||
|
|
||||||
|
lp.sec("waiting for the reply message from the bot to arrive")
|
||||||
|
reply = ac1._evtracker.wait_next_incoming_message()
|
||||||
|
assert reply.chat == bot_chat
|
||||||
|
assert "hello" in reply.text
|
||||||
|
lp.sec("send quit sequence")
|
||||||
|
bot_chat.send_text("/quit")
|
||||||
|
botproc.wait()
|
||||||
|
|
||||||
|
|
||||||
|
def test_group_tracking_plugin(acfactory, lp):
|
||||||
|
lp.sec("creating one group-tracking bot and two temp accounts")
|
||||||
|
botproc = acfactory.run_bot_process(group_tracking, ffi=False)
|
||||||
|
|
||||||
|
ac1, ac2 = acfactory.get_two_online_accounts(quiet=True)
|
||||||
|
|
||||||
|
botproc.fnmatch_lines("""
|
||||||
|
*ac_configure_completed*
|
||||||
|
""")
|
||||||
|
ac1.add_account_plugin(FFIEventLogger(ac1))
|
||||||
|
ac2.add_account_plugin(FFIEventLogger(ac2))
|
||||||
|
|
||||||
|
lp.sec("creating bot test group with bot")
|
||||||
|
bot_contact = ac1.create_contact(botproc.addr)
|
||||||
|
ch = ac1.create_group_chat("bot test group")
|
||||||
|
ch.add_contact(bot_contact)
|
||||||
|
ch.send_text("hello")
|
||||||
|
|
||||||
|
botproc.fnmatch_lines("""
|
||||||
|
*ac_chat_modified*bot test group*
|
||||||
|
""")
|
||||||
|
|
||||||
|
lp.sec("adding third member {}".format(ac2.get_config("addr")))
|
||||||
|
contact3 = ac1.create_contact(ac2.get_config("addr"))
|
||||||
|
ch.add_contact(contact3)
|
||||||
|
|
||||||
|
reply = ac1._evtracker.wait_next_incoming_message()
|
||||||
|
assert "hello" in reply.text
|
||||||
|
|
||||||
|
lp.sec("now looking at what the bot received")
|
||||||
|
botproc.fnmatch_lines("""
|
||||||
|
*ac_member_added {}*
|
||||||
|
""".format(contact3.addr))
|
||||||
|
|
||||||
|
lp.sec("contact successfully added, now removing")
|
||||||
|
ch.remove_contact(contact3)
|
||||||
|
botproc.fnmatch_lines("""
|
||||||
|
*ac_member_removed {}*
|
||||||
|
""".format(contact3.addr))
|
||||||
7
python/fail_test.py
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
from __future__ import print_function
|
||||||
|
from deltachat import capi
|
||||||
|
from deltachat.capi import ffi, lib
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
ctx = capi.lib.dc_context_new(ffi.NULL, ffi.NULL)
|
||||||
|
lib.dc_stop_io(ctx)
|
||||||
@@ -6,20 +6,24 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import os
|
import sys
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
os.environ["DCC_RS_TARGET"] = target = "release"
|
target = os.environ.get("DCC_RS_TARGET")
|
||||||
|
if target is None:
|
||||||
|
os.environ["DCC_RS_TARGET"] = target = "debug"
|
||||||
if "DCC_RS_DEV" not in os.environ:
|
if "DCC_RS_DEV" not in os.environ:
|
||||||
dn = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
dn = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||||
os.environ["DCC_RS_DEV"] = dn
|
os.environ["DCC_RS_DEV"] = dn
|
||||||
|
|
||||||
os.environ["RUSTFLAGS"] = "-g"
|
cmd = ["cargo", "build", "-p", "deltachat_ffi"]
|
||||||
subprocess.check_call([
|
if target == 'release':
|
||||||
"cargo", "build", "-p", "deltachat_ffi", "--" + target
|
cmd.append("--release")
|
||||||
])
|
print("running:", " ".join(cmd))
|
||||||
|
subprocess.check_call(cmd)
|
||||||
subprocess.check_call("rm -rf build/ src/deltachat/*.so" , shell=True)
|
subprocess.check_call("rm -rf build/ src/deltachat/*.so" , shell=True)
|
||||||
|
|
||||||
|
if len(sys.argv) <= 1 or sys.argv[1] != "onlybuild":
|
||||||
subprocess.check_call([
|
subprocess.check_call([
|
||||||
"pip", "install", "-e", "."
|
sys.executable, "-m", "pip", "install", "-e", "."
|
||||||
])
|
])
|
||||||
|
|||||||
@@ -13,14 +13,20 @@ def main():
|
|||||||
"root": "..",
|
"root": "..",
|
||||||
"relative_to": __file__,
|
"relative_to": __file__,
|
||||||
'tag_regex': r'^(?P<prefix>py-)?(?P<version>[^\+]+)(?P<suffix>.*)?$',
|
'tag_regex': r'^(?P<prefix>py-)?(?P<version>[^\+]+)(?P<suffix>.*)?$',
|
||||||
|
'git_describe_command': "git describe --dirty --tags --long --match py-*.*",
|
||||||
},
|
},
|
||||||
description='Python bindings for the Delta Chat Core library using CFFI against the Rust-implemented libdeltachat',
|
description='Python bindings for the Delta Chat Core library using CFFI against the Rust-implemented libdeltachat',
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
author='holger krekel, Floris Bruynooghe, Bjoern Petersen and contributors',
|
author='holger krekel, Floris Bruynooghe, Bjoern Petersen and contributors',
|
||||||
install_requires=['cffi>=1.0.0', 'six'],
|
install_requires=['cffi>=1.0.0', 'pluggy', 'imapclient'],
|
||||||
packages=setuptools.find_packages('src'),
|
packages=setuptools.find_packages('src'),
|
||||||
package_dir={'': 'src'},
|
package_dir={'': 'src'},
|
||||||
cffi_modules=['src/deltachat/_build.py:ffibuilder'],
|
cffi_modules=['src/deltachat/_build.py:ffibuilder'],
|
||||||
|
entry_points = {
|
||||||
|
'pytest11': [
|
||||||
|
'deltachat.testplugin = deltachat.testplugin',
|
||||||
|
],
|
||||||
|
},
|
||||||
classifiers=[
|
classifiers=[
|
||||||
'Development Status :: 4 - Beta',
|
'Development Status :: 4 - Beta',
|
||||||
'Intended Audience :: Developers',
|
'Intended Audience :: Developers',
|
||||||
|
|||||||
@@ -1,6 +1,13 @@
|
|||||||
from deltachat import capi, const
|
import sys
|
||||||
from deltachat.capi import ffi
|
|
||||||
from deltachat.account import Account # noqa
|
from . import capi, const, hookspec # noqa
|
||||||
|
from .capi import ffi # noqa
|
||||||
|
from .account import Account # noqa
|
||||||
|
from .message import Message # noqa
|
||||||
|
from .contact import Contact # noqa
|
||||||
|
from .chat import Chat # noqa
|
||||||
|
from .hookspec import account_hookimpl, global_hookimpl # noqa
|
||||||
|
from . import events
|
||||||
|
|
||||||
from pkg_resources import get_distribution, DistributionNotFound
|
from pkg_resources import get_distribution, DistributionNotFound
|
||||||
try:
|
try:
|
||||||
@@ -10,67 +17,72 @@ except DistributionNotFound:
|
|||||||
__version__ = "0.0.0.dev0-unknown"
|
__version__ = "0.0.0.dev0-unknown"
|
||||||
|
|
||||||
|
|
||||||
_DC_CALLBACK_MAP = {}
|
|
||||||
|
|
||||||
|
|
||||||
@capi.ffi.def_extern()
|
|
||||||
def py_dc_callback(ctx, evt, data1, data2):
|
|
||||||
"""The global event handler.
|
|
||||||
|
|
||||||
CFFI only allows us to set one global event handler, so this one
|
|
||||||
looks up the correct event handler for the given context.
|
|
||||||
"""
|
|
||||||
try:
|
|
||||||
callback = _DC_CALLBACK_MAP.get(ctx, lambda *a: 0)
|
|
||||||
except AttributeError:
|
|
||||||
# we are in a deep in GC-free/interpreter shutdown land
|
|
||||||
# nothing much better to do here than:
|
|
||||||
return 0
|
|
||||||
|
|
||||||
# the following code relates to the deltachat/_build.py's helper
|
|
||||||
# function which provides us signature info of an event call
|
|
||||||
evt_name = get_dc_event_name(evt)
|
|
||||||
event_sig_types = capi.lib.dc_get_event_signature_types(evt)
|
|
||||||
if data1 and event_sig_types & 1:
|
|
||||||
data1 = ffi.string(ffi.cast('char*', data1)).decode("utf8")
|
|
||||||
if data2 and event_sig_types & 2:
|
|
||||||
data2 = ffi.string(ffi.cast('char*', data2)).decode("utf8")
|
|
||||||
try:
|
|
||||||
if isinstance(data2, bytes):
|
|
||||||
data2 = data2.decode("utf8")
|
|
||||||
except UnicodeDecodeError:
|
|
||||||
# XXX ignoring the decode error is not quite correct but for now
|
|
||||||
# i don't want to hunt down encoding problems in the c lib
|
|
||||||
pass
|
|
||||||
try:
|
|
||||||
ret = callback(ctx, evt_name, data1, data2)
|
|
||||||
if ret is None:
|
|
||||||
ret = 0
|
|
||||||
assert isinstance(ret, int), repr(ret)
|
|
||||||
if event_sig_types & 4:
|
|
||||||
return ffi.cast('uintptr_t', ret)
|
|
||||||
elif event_sig_types & 8:
|
|
||||||
return ffi.cast('int', ret)
|
|
||||||
except: # noqa
|
|
||||||
raise
|
|
||||||
ret = 0
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
def set_context_callback(dc_context, func):
|
|
||||||
_DC_CALLBACK_MAP[dc_context] = func
|
|
||||||
|
|
||||||
|
|
||||||
def clear_context_callback(dc_context):
|
|
||||||
try:
|
|
||||||
_DC_CALLBACK_MAP.pop(dc_context, None)
|
|
||||||
except AttributeError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
def get_dc_event_name(integer, _DC_EVENTNAME_MAP={}):
|
def get_dc_event_name(integer, _DC_EVENTNAME_MAP={}):
|
||||||
if not _DC_EVENTNAME_MAP:
|
if not _DC_EVENTNAME_MAP:
|
||||||
for name, val in vars(const).items():
|
for name, val in vars(const).items():
|
||||||
if name.startswith("DC_EVENT_"):
|
if name.startswith("DC_EVENT_"):
|
||||||
_DC_EVENTNAME_MAP[val] = name
|
_DC_EVENTNAME_MAP[val] = name
|
||||||
return _DC_EVENTNAME_MAP[integer]
|
return _DC_EVENTNAME_MAP[integer]
|
||||||
|
|
||||||
|
|
||||||
|
def register_global_plugin(plugin):
|
||||||
|
""" Register a global plugin which implements one or more
|
||||||
|
of the :class:`deltachat.hookspec.Global` hooks.
|
||||||
|
"""
|
||||||
|
gm = hookspec.Global._get_plugin_manager()
|
||||||
|
gm.register(plugin)
|
||||||
|
gm.check_pending()
|
||||||
|
|
||||||
|
|
||||||
|
def unregister_global_plugin(plugin):
|
||||||
|
gm = hookspec.Global._get_plugin_manager()
|
||||||
|
gm.unregister(plugin)
|
||||||
|
|
||||||
|
|
||||||
|
register_global_plugin(events)
|
||||||
|
|
||||||
|
|
||||||
|
def run_cmdline(argv=None, account_plugins=None):
|
||||||
|
""" Run a simple default command line app, registering the specified
|
||||||
|
account plugins. """
|
||||||
|
import argparse
|
||||||
|
if argv is None:
|
||||||
|
argv = sys.argv
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(prog=argv[0] if argv else None)
|
||||||
|
parser.add_argument("db", action="store", help="database file")
|
||||||
|
parser.add_argument("--show-ffi", action="store_true", help="show low level ffi events")
|
||||||
|
parser.add_argument("--email", action="store", help="email address")
|
||||||
|
parser.add_argument("--password", action="store", help="password")
|
||||||
|
|
||||||
|
args = parser.parse_args(argv[1:])
|
||||||
|
|
||||||
|
ac = Account(args.db)
|
||||||
|
|
||||||
|
if args.show_ffi:
|
||||||
|
ac.set_config("displayname", "bot")
|
||||||
|
log = events.FFIEventLogger(ac)
|
||||||
|
ac.add_account_plugin(log)
|
||||||
|
|
||||||
|
for plugin in account_plugins or []:
|
||||||
|
print("adding plugin", plugin)
|
||||||
|
ac.add_account_plugin(plugin)
|
||||||
|
|
||||||
|
if not ac.is_configured():
|
||||||
|
assert args.email and args.password, (
|
||||||
|
"you must specify --email and --password once to configure this database/account"
|
||||||
|
)
|
||||||
|
ac.set_config("addr", args.email)
|
||||||
|
ac.set_config("mail_pw", args.password)
|
||||||
|
ac.set_config("mvbox_move", "0")
|
||||||
|
ac.set_config("mvbox_watch", "0")
|
||||||
|
ac.set_config("sentbox_watch", "0")
|
||||||
|
configtracker = ac.configure()
|
||||||
|
configtracker.wait_finish()
|
||||||
|
|
||||||
|
# start IO threads and configure if neccessary
|
||||||
|
ac.start_io()
|
||||||
|
|
||||||
|
print("{}: waiting for message".format(ac.get_config("addr")))
|
||||||
|
|
||||||
|
ac.wait_shutdown()
|
||||||
|
|||||||
@@ -1,76 +1,64 @@
|
|||||||
import distutils.ccompiler
|
import distutils.ccompiler
|
||||||
import distutils.log
|
import distutils.log
|
||||||
import distutils.sysconfig
|
import distutils.sysconfig
|
||||||
import tempfile
|
|
||||||
import platform
|
|
||||||
import os
|
import os
|
||||||
import cffi
|
import platform
|
||||||
|
import re
|
||||||
import shutil
|
import shutil
|
||||||
from os.path import dirname as dn
|
import subprocess
|
||||||
|
import tempfile
|
||||||
|
import textwrap
|
||||||
|
import types
|
||||||
from os.path import abspath
|
from os.path import abspath
|
||||||
|
from os.path import dirname as dn
|
||||||
|
|
||||||
|
import cffi
|
||||||
|
|
||||||
|
|
||||||
def ffibuilder():
|
def local_build_flags(projdir, target):
|
||||||
projdir = os.environ.get('DCC_RS_DEV')
|
"""Construct build flags for building against a checkout.
|
||||||
if not projdir:
|
|
||||||
p = dn(dn(dn(dn(abspath(__file__)))))
|
:param projdir: The root directory of the deltachat-core-rust project.
|
||||||
projdir = os.environ["DCC_RS_DEV"] = p
|
:param target: The rust build target, `debug` or `release`.
|
||||||
target = os.environ.get('DCC_RS_TARGET', 'release')
|
"""
|
||||||
if projdir:
|
flags = types.SimpleNamespace()
|
||||||
if platform.system() == 'Darwin':
|
if platform.system() == 'Darwin':
|
||||||
libs = ['resolv', 'dl']
|
flags.libs = ['resolv', 'dl']
|
||||||
extra_link_args = [
|
flags.extra_link_args = [
|
||||||
'-framework', 'CoreFoundation',
|
'-framework', 'CoreFoundation',
|
||||||
'-framework', 'CoreServices',
|
'-framework', 'CoreServices',
|
||||||
'-framework', 'Security',
|
'-framework', 'Security',
|
||||||
]
|
]
|
||||||
elif platform.system() == 'Linux':
|
elif platform.system() == 'Linux':
|
||||||
libs = ['rt', 'dl', 'm']
|
flags.libs = ['rt', 'dl', 'm']
|
||||||
extra_link_args = []
|
flags.extra_link_args = []
|
||||||
else:
|
else:
|
||||||
raise NotImplementedError("Compilation not supported yet on Windows, can you help?")
|
raise NotImplementedError("Compilation not supported yet on Windows, can you help?")
|
||||||
objs = [os.path.join(projdir, 'target', target, 'libdeltachat.a')]
|
target_dir = os.environ.get("CARGO_TARGET_DIR")
|
||||||
assert os.path.exists(objs[0]), objs
|
if target_dir is None:
|
||||||
incs = [os.path.join(projdir, 'deltachat-ffi')]
|
target_dir = os.path.join(projdir, 'target')
|
||||||
else:
|
flags.objs = [os.path.join(target_dir, target, 'libdeltachat.a')]
|
||||||
libs = ['deltachat']
|
assert os.path.exists(flags.objs[0]), flags.objs
|
||||||
objs = []
|
flags.incs = [os.path.join(projdir, 'deltachat-ffi')]
|
||||||
incs = []
|
return flags
|
||||||
extra_link_args = []
|
|
||||||
builder = cffi.FFI()
|
|
||||||
builder.set_source(
|
def system_build_flags():
|
||||||
'deltachat.capi',
|
"""Construct build flags for building against an installed libdeltachat."""
|
||||||
|
flags = types.SimpleNamespace()
|
||||||
|
flags.libs = ['deltachat']
|
||||||
|
flags.objs = []
|
||||||
|
flags.incs = []
|
||||||
|
flags.extra_link_args = []
|
||||||
|
|
||||||
|
|
||||||
|
def extract_functions(flags):
|
||||||
|
"""Extract the function definitions from deltachat.h.
|
||||||
|
|
||||||
|
This creates a .h file with a single `#include <deltachat.h>` line
|
||||||
|
in it. It then runs the C preprocessor to create an output file
|
||||||
|
which contains all function definitions found in `deltachat.h`.
|
||||||
"""
|
"""
|
||||||
#include <deltachat.h>
|
|
||||||
const char * dupstring_helper(const char* string)
|
|
||||||
{
|
|
||||||
return strdup(string);
|
|
||||||
}
|
|
||||||
int dc_get_event_signature_types(int e)
|
|
||||||
{
|
|
||||||
int result = 0;
|
|
||||||
if (DC_EVENT_DATA1_IS_STRING(e))
|
|
||||||
result |= 1;
|
|
||||||
if (DC_EVENT_DATA2_IS_STRING(e))
|
|
||||||
result |= 2;
|
|
||||||
if (DC_EVENT_RETURNS_STRING(e))
|
|
||||||
result |= 4;
|
|
||||||
if (DC_EVENT_RETURNS_INT(e))
|
|
||||||
result |= 8;
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
""",
|
|
||||||
include_dirs=incs,
|
|
||||||
libraries=libs,
|
|
||||||
extra_objects=objs,
|
|
||||||
extra_link_args=extra_link_args,
|
|
||||||
)
|
|
||||||
builder.cdef("""
|
|
||||||
typedef int... time_t;
|
|
||||||
void free(void *ptr);
|
|
||||||
extern const char * dupstring_helper(const char* string);
|
|
||||||
extern int dc_get_event_signature_types(int);
|
|
||||||
""")
|
|
||||||
distutils.log.set_verbosity(distutils.log.INFO)
|
distutils.log.set_verbosity(distutils.log.INFO)
|
||||||
cc = distutils.ccompiler.new_compiler(force=True)
|
cc = distutils.ccompiler.new_compiler(force=True)
|
||||||
distutils.sysconfig.customize_compiler(cc)
|
distutils.sysconfig.customize_compiler(cc)
|
||||||
@@ -82,20 +70,133 @@ def ffibuilder():
|
|||||||
src_fp.write('#include <deltachat.h>')
|
src_fp.write('#include <deltachat.h>')
|
||||||
cc.preprocess(source=src_name,
|
cc.preprocess(source=src_name,
|
||||||
output_file=dst_name,
|
output_file=dst_name,
|
||||||
include_dirs=incs,
|
include_dirs=flags.incs,
|
||||||
macros=[('PY_CFFI', '1')])
|
macros=[('PY_CFFI', '1')])
|
||||||
with open(dst_name, "r") as dst_fp:
|
with open(dst_name, "r") as dst_fp:
|
||||||
builder.cdef(dst_fp.read())
|
return dst_fp.read()
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(tmpdir)
|
shutil.rmtree(tmpdir)
|
||||||
|
|
||||||
|
|
||||||
|
def find_header(flags):
|
||||||
|
"""Use the compiler to find the deltachat.h header location.
|
||||||
|
|
||||||
|
This uses a small utility in deltachat.h to find the location of
|
||||||
|
the header file location.
|
||||||
|
"""
|
||||||
|
distutils.log.set_verbosity(distutils.log.INFO)
|
||||||
|
cc = distutils.ccompiler.new_compiler(force=True)
|
||||||
|
distutils.sysconfig.customize_compiler(cc)
|
||||||
|
tmpdir = tempfile.mkdtemp()
|
||||||
|
try:
|
||||||
|
src_name = os.path.join(tmpdir, "where.c")
|
||||||
|
obj_name = os.path.join(tmpdir, "where.o")
|
||||||
|
dst_name = os.path.join(tmpdir, "where")
|
||||||
|
with open(src_name, "w") as src_fp:
|
||||||
|
src_fp.write(textwrap.dedent("""
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <deltachat.h>
|
||||||
|
|
||||||
|
int main(void) {
|
||||||
|
printf("%s", _dc_header_file_location());
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
"""))
|
||||||
|
cwd = os.getcwd()
|
||||||
|
try:
|
||||||
|
os.chdir(tmpdir)
|
||||||
|
cc.compile(sources=["where.c"],
|
||||||
|
include_dirs=flags.incs,
|
||||||
|
macros=[("PY_CFFI_INC", "1")])
|
||||||
|
finally:
|
||||||
|
os.chdir(cwd)
|
||||||
|
cc.link_executable(objects=[obj_name],
|
||||||
|
output_progname="where",
|
||||||
|
output_dir=tmpdir)
|
||||||
|
return subprocess.check_output(dst_name)
|
||||||
|
finally:
|
||||||
|
shutil.rmtree(tmpdir)
|
||||||
|
|
||||||
|
|
||||||
|
def extract_defines(flags):
|
||||||
|
"""Extract the required #DEFINEs from deltachat.h.
|
||||||
|
|
||||||
|
Since #DEFINEs are interpreted by the C preprocessor we can not
|
||||||
|
use the compiler to extract these and need to parse the header
|
||||||
|
file ourselves.
|
||||||
|
|
||||||
|
The defines are returned in a string that can be passed to CFFIs
|
||||||
|
cdef() method.
|
||||||
|
"""
|
||||||
|
header = find_header(flags)
|
||||||
|
defines_re = re.compile(r"""
|
||||||
|
\#define\s+ # The start of a define.
|
||||||
|
( # Begin capturing group which captures the define name.
|
||||||
|
(?: # A nested group which is not captured, this allows us
|
||||||
|
# to build the list of prefixes to extract without
|
||||||
|
# creation another capture group.
|
||||||
|
DC_EVENT
|
||||||
|
| DC_QR
|
||||||
|
| DC_MSG
|
||||||
|
| DC_LP
|
||||||
|
| DC_EMPTY
|
||||||
|
| DC_CERTCK
|
||||||
|
| DC_STATE
|
||||||
|
| DC_STR
|
||||||
|
| DC_CONTACT_ID
|
||||||
|
| DC_GCL
|
||||||
|
| DC_CHAT
|
||||||
|
| DC_PROVIDER
|
||||||
|
| DC_KEY_GEN
|
||||||
|
) # End of prefix matching
|
||||||
|
_[\w_]+ # Match the suffix, e.g. _RSA2048 in DC_KEY_GEN_RSA2048
|
||||||
|
) # Close the capturing group, this contains
|
||||||
|
# the entire name e.g. DC_MSG_TEXT.
|
||||||
|
\s+\S+ # Ensure there is whitespace followed by a value.
|
||||||
|
""", re.VERBOSE)
|
||||||
|
defines = []
|
||||||
|
with open(header) as fp:
|
||||||
|
for line in fp:
|
||||||
|
match = defines_re.match(line)
|
||||||
|
if match:
|
||||||
|
defines.append(match.group(1))
|
||||||
|
return '\n'.join('#define {} ...'.format(d) for d in defines)
|
||||||
|
|
||||||
|
|
||||||
|
def ffibuilder():
|
||||||
|
projdir = os.environ.get('DCC_RS_DEV')
|
||||||
|
if not projdir:
|
||||||
|
p = dn(dn(dn(dn(abspath(__file__)))))
|
||||||
|
projdir = os.environ["DCC_RS_DEV"] = p
|
||||||
|
target = os.environ.get('DCC_RS_TARGET', 'release')
|
||||||
|
if projdir:
|
||||||
|
flags = local_build_flags(projdir, target)
|
||||||
|
else:
|
||||||
|
flags = system_build_flags()
|
||||||
|
builder = cffi.FFI()
|
||||||
|
builder.set_source(
|
||||||
|
'deltachat.capi',
|
||||||
|
"""
|
||||||
|
#include <deltachat.h>
|
||||||
|
int dc_event_has_string_data(int e)
|
||||||
|
{
|
||||||
|
return DC_EVENT_DATA2_IS_STRING(e);
|
||||||
|
}
|
||||||
|
""",
|
||||||
|
include_dirs=flags.incs,
|
||||||
|
libraries=flags.libs,
|
||||||
|
extra_objects=flags.objs,
|
||||||
|
extra_link_args=flags.extra_link_args,
|
||||||
|
)
|
||||||
builder.cdef("""
|
builder.cdef("""
|
||||||
extern "Python" uintptr_t py_dc_callback(
|
typedef int... time_t;
|
||||||
dc_context_t* context,
|
void free(void *ptr);
|
||||||
int event,
|
extern int dc_event_has_string_data(int);
|
||||||
uintptr_t data1,
|
|
||||||
uintptr_t data2);
|
|
||||||
""")
|
""")
|
||||||
|
function_defs = extract_functions(flags)
|
||||||
|
defines = extract_defines(flags)
|
||||||
|
builder.cdef(function_defs)
|
||||||
|
builder.cdef(defines)
|
||||||
return builder
|
return builder
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,59 +1,78 @@
|
|||||||
""" Account class implementation. """
|
""" Account class implementation. """
|
||||||
|
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
import threading
|
from contextlib import contextmanager
|
||||||
|
from email.utils import parseaddr
|
||||||
|
from threading import Event
|
||||||
import os
|
import os
|
||||||
import re
|
|
||||||
import time
|
|
||||||
from array import array
|
from array import array
|
||||||
try:
|
|
||||||
from queue import Queue, Empty
|
|
||||||
except ImportError:
|
|
||||||
from Queue import Queue, Empty
|
|
||||||
|
|
||||||
import deltachat
|
|
||||||
from . import const
|
from . import const
|
||||||
from .capi import ffi, lib
|
from .capi import ffi, lib
|
||||||
from .cutil import as_dc_charpointer, from_dc_charpointer, iter_array
|
from .cutil import as_dc_charpointer, from_dc_charpointer, iter_array, DCLot
|
||||||
from .chatting import Contact, Chat, Message
|
from .chat import Chat
|
||||||
|
from .message import Message
|
||||||
|
from .contact import Contact
|
||||||
|
from .tracker import ImexTracker, ConfigureTracker
|
||||||
|
from . import hookspec
|
||||||
|
from .events import EventThread
|
||||||
|
|
||||||
|
|
||||||
|
class MissingCredentials(ValueError):
|
||||||
|
""" Account is missing `addr` and `mail_pw` config values. """
|
||||||
|
|
||||||
|
|
||||||
class Account(object):
|
class Account(object):
|
||||||
""" Each account is tied to a sqlite database file which is fully managed
|
""" Each account is tied to a sqlite database file which is fully managed
|
||||||
by the underlying deltachat c-library. All public Account methods are
|
by the underlying deltachat core library. All public Account methods are
|
||||||
meant to be memory-safe and return memory-safe objects.
|
meant to be memory-safe and return memory-safe objects.
|
||||||
"""
|
"""
|
||||||
def __init__(self, db_path, logid=None, eventlogging=True):
|
MissingCredentials = MissingCredentials
|
||||||
|
|
||||||
|
def __init__(self, db_path, os_name=None, logging=True):
|
||||||
""" initialize account object.
|
""" initialize account object.
|
||||||
|
|
||||||
:param db_path: a path to the account database. The database
|
:param db_path: a path to the account database. The database
|
||||||
will be created if it doesn't exist.
|
will be created if it doesn't exist.
|
||||||
:param logid: an optional logging prefix that should be used with
|
:param os_name: this will be put to the X-Mailer header in outgoing messages
|
||||||
the default internal logging.
|
|
||||||
:param eventlogging: if False no eventlogging and no context callback will be configured
|
|
||||||
"""
|
"""
|
||||||
self._dc_context = ffi.gc(
|
# initialize per-account plugin system
|
||||||
lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL),
|
self._pm = hookspec.PerAccount._make_plugin_manager()
|
||||||
_destroy_dc_context,
|
self._logging = logging
|
||||||
)
|
|
||||||
if eventlogging:
|
|
||||||
self._evlogger = EventLogger(self._dc_context, logid)
|
|
||||||
deltachat.set_context_callback(self._dc_context, self._process_event)
|
|
||||||
self._threads = IOThreads(self._dc_context, self._evlogger._log_event)
|
|
||||||
else:
|
|
||||||
self._threads = IOThreads(self._dc_context)
|
|
||||||
|
|
||||||
|
self.add_account_plugin(self)
|
||||||
|
|
||||||
|
self.db_path = db_path
|
||||||
if hasattr(db_path, "encode"):
|
if hasattr(db_path, "encode"):
|
||||||
db_path = db_path.encode("utf8")
|
db_path = db_path.encode("utf8")
|
||||||
if not lib.dc_open(self._dc_context, db_path, ffi.NULL):
|
|
||||||
raise ValueError("Could not dc_open: {}".format(db_path))
|
|
||||||
self._configkeys = self.get_config("sys.config_keys").split()
|
|
||||||
self._imex_completed = threading.Event()
|
|
||||||
|
|
||||||
# XXX this can cause "illegal instructions" at test ends so we omit it for now
|
self._dc_context = ffi.gc(
|
||||||
|
lib.dc_context_new(as_dc_charpointer(os_name), db_path, ffi.NULL),
|
||||||
|
lib.dc_context_unref,
|
||||||
|
)
|
||||||
|
if self._dc_context == ffi.NULL:
|
||||||
|
raise ValueError("Could not dc_context_new: {} {}".format(os_name, db_path))
|
||||||
|
|
||||||
|
self._shutdown_event = Event()
|
||||||
|
self._event_thread = EventThread(self)
|
||||||
|
self._configkeys = self.get_config("sys.config_keys").split()
|
||||||
|
hook = hookspec.Global._get_plugin_manager().hook
|
||||||
|
hook.dc_account_init(account=self)
|
||||||
|
|
||||||
|
def disable_logging(self):
|
||||||
|
""" disable logging. """
|
||||||
|
self._logging = False
|
||||||
|
|
||||||
|
def enable_logging(self):
|
||||||
|
""" re-enable logging. """
|
||||||
|
self._logging = True
|
||||||
|
|
||||||
# def __del__(self):
|
# def __del__(self):
|
||||||
# self.shutdown()
|
# self.shutdown()
|
||||||
|
|
||||||
|
def log(self, msg):
|
||||||
|
if self._logging:
|
||||||
|
self._pm.hook.ac_log_line(message=msg)
|
||||||
|
|
||||||
def _check_config_key(self, name):
|
def _check_config_key(self, name):
|
||||||
if name not in self._configkeys:
|
if name not in self._configkeys:
|
||||||
raise KeyError("{!r} not a valid config key, existing keys: {!r}".format(
|
raise KeyError("{!r} not a valid config key, existing keys: {!r}".format(
|
||||||
@@ -70,6 +89,18 @@ class Account(object):
|
|||||||
d[key.lower()] = value
|
d[key.lower()] = value
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
def set_stock_translation(self, id, string):
|
||||||
|
""" set stock translation string.
|
||||||
|
|
||||||
|
:param id: id of stock string (const.DC_STR_*)
|
||||||
|
:param value: string to set as new transalation
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
string = string.encode("utf8")
|
||||||
|
res = lib.dc_set_stock_translation(self._dc_context, id, string)
|
||||||
|
if res == 0:
|
||||||
|
raise ValueError("could not set translation string")
|
||||||
|
|
||||||
def set_config(self, name, value):
|
def set_config(self, name, value):
|
||||||
""" set configuration values.
|
""" set configuration values.
|
||||||
|
|
||||||
@@ -79,9 +110,12 @@ class Account(object):
|
|||||||
"""
|
"""
|
||||||
self._check_config_key(name)
|
self._check_config_key(name)
|
||||||
name = name.encode("utf8")
|
name = name.encode("utf8")
|
||||||
value = value.encode("utf8")
|
|
||||||
if name == b"addr" and self.is_configured():
|
if name == b"addr" and self.is_configured():
|
||||||
raise ValueError("can not change 'addr' after account is configured.")
|
raise ValueError("can not change 'addr' after account is configured.")
|
||||||
|
if value is not None:
|
||||||
|
value = value.encode("utf8")
|
||||||
|
else:
|
||||||
|
value = ffi.NULL
|
||||||
lib.dc_set_config(self._dc_context, name, value)
|
lib.dc_set_config(self._dc_context, name, value)
|
||||||
|
|
||||||
def get_config(self, name):
|
def get_config(self, name):
|
||||||
@@ -98,16 +132,27 @@ class Account(object):
|
|||||||
assert res != ffi.NULL, "config value not found for: {!r}".format(name)
|
assert res != ffi.NULL, "config value not found for: {!r}".format(name)
|
||||||
return from_dc_charpointer(res)
|
return from_dc_charpointer(res)
|
||||||
|
|
||||||
def configure(self, **kwargs):
|
def _preconfigure_keypair(self, addr, public, secret):
|
||||||
""" set config values and configure this account.
|
"""See dc_preconfigure_keypair() in deltachat.h.
|
||||||
|
|
||||||
|
In other words, you don't need this.
|
||||||
|
"""
|
||||||
|
res = lib.dc_preconfigure_keypair(self._dc_context,
|
||||||
|
as_dc_charpointer(addr),
|
||||||
|
as_dc_charpointer(public),
|
||||||
|
as_dc_charpointer(secret))
|
||||||
|
if res == 0:
|
||||||
|
raise Exception("Failed to set key")
|
||||||
|
|
||||||
|
def update_config(self, kwargs):
|
||||||
|
""" update config values.
|
||||||
|
|
||||||
:param kwargs: name=value config settings for this account.
|
:param kwargs: name=value config settings for this account.
|
||||||
values need to be unicode.
|
values need to be unicode.
|
||||||
:returns: None
|
:returns: None
|
||||||
"""
|
"""
|
||||||
for name, value in kwargs.items():
|
for key, value in kwargs.items():
|
||||||
self.set_config(name, value)
|
self.set_config(key, str(value))
|
||||||
lib.dc_configure(self._dc_context)
|
|
||||||
|
|
||||||
def is_configured(self):
|
def is_configured(self):
|
||||||
""" determine if the account is configured already; an initial connection
|
""" determine if the account is configured already; an initial connection
|
||||||
@@ -115,17 +160,43 @@ class Account(object):
|
|||||||
|
|
||||||
:returns: True if account is configured.
|
:returns: True if account is configured.
|
||||||
"""
|
"""
|
||||||
return lib.dc_is_configured(self._dc_context)
|
return True if lib.dc_is_configured(self._dc_context) else False
|
||||||
|
|
||||||
|
def set_avatar(self, img_path):
|
||||||
|
"""Set self avatar.
|
||||||
|
|
||||||
|
:raises ValueError: if profile image could not be set
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
if img_path is None:
|
||||||
|
self.set_config("selfavatar", None)
|
||||||
|
else:
|
||||||
|
assert os.path.exists(img_path), img_path
|
||||||
|
self.set_config("selfavatar", img_path)
|
||||||
|
|
||||||
def check_is_configured(self):
|
def check_is_configured(self):
|
||||||
""" Raise ValueError if this account is not configured. """
|
""" Raise ValueError if this account is not configured. """
|
||||||
if not self.is_configured():
|
if not self.is_configured():
|
||||||
raise ValueError("need to configure first")
|
raise ValueError("need to configure first")
|
||||||
|
|
||||||
def get_infostring(self):
|
def empty_server_folders(self, inbox=False, mvbox=False):
|
||||||
""" return info of the configured account. """
|
""" empty server folders. """
|
||||||
self.check_is_configured()
|
flags = 0
|
||||||
return from_dc_charpointer(lib.dc_get_info(self._dc_context))
|
if inbox:
|
||||||
|
flags |= const.DC_EMPTY_INBOX
|
||||||
|
if mvbox:
|
||||||
|
flags |= const.DC_EMPTY_MVBOX
|
||||||
|
if not flags:
|
||||||
|
raise ValueError("no flags set")
|
||||||
|
lib.dc_empty_server(self._dc_context, flags)
|
||||||
|
|
||||||
|
def get_latest_backupfile(self, backupdir):
|
||||||
|
""" return the latest backup file in a given directory.
|
||||||
|
"""
|
||||||
|
res = lib.dc_imex_has_backup(self._dc_context, as_dc_charpointer(backupdir))
|
||||||
|
if res == ffi.NULL:
|
||||||
|
return None
|
||||||
|
return from_dc_charpointer(res)
|
||||||
|
|
||||||
def get_blobdir(self):
|
def get_blobdir(self):
|
||||||
""" return the directory for files.
|
""" return the directory for files.
|
||||||
@@ -136,27 +207,47 @@ class Account(object):
|
|||||||
return from_dc_charpointer(lib.dc_get_blobdir(self._dc_context))
|
return from_dc_charpointer(lib.dc_get_blobdir(self._dc_context))
|
||||||
|
|
||||||
def get_self_contact(self):
|
def get_self_contact(self):
|
||||||
""" return this account's identity as a :class:`deltachat.chatting.Contact`.
|
""" return this account's identity as a :class:`deltachat.contact.Contact`.
|
||||||
|
|
||||||
:returns: :class:`deltachat.chatting.Contact`
|
:returns: :class:`deltachat.contact.Contact`
|
||||||
"""
|
"""
|
||||||
self.check_is_configured()
|
return Contact(self, const.DC_CONTACT_ID_SELF)
|
||||||
return Contact(self._dc_context, const.DC_CONTACT_ID_SELF)
|
|
||||||
|
|
||||||
def create_contact(self, email, name=None):
|
def create_contact(self, obj, name=None):
|
||||||
""" create a (new) Contact. If there already is a Contact
|
""" create a (new) Contact or return an existing one.
|
||||||
with that e-mail address, it is unblocked and its name is
|
|
||||||
updated.
|
|
||||||
|
|
||||||
:param email: email-address (text type)
|
Calling this method will always resulut in the same
|
||||||
:param name: display name for this contact (optional)
|
underlying contact id. If there already is a Contact
|
||||||
:returns: :class:`deltachat.chatting.Contact` instance.
|
with that e-mail address, it is unblocked and its display
|
||||||
|
`name` is updated if specified.
|
||||||
|
|
||||||
|
:param obj: email-address, Account or Contact instance.
|
||||||
|
:param name: (optional) display name for this contact
|
||||||
|
:returns: :class:`deltachat.contact.Contact` instance.
|
||||||
"""
|
"""
|
||||||
|
if isinstance(obj, Account):
|
||||||
|
if not obj.is_configured():
|
||||||
|
raise ValueError("can only add addresses from configured accounts")
|
||||||
|
addr, displayname = obj.get_config("addr"), obj.get_config("displayname")
|
||||||
|
elif isinstance(obj, Contact):
|
||||||
|
if obj.account != self:
|
||||||
|
raise ValueError("account mismatch {}".format(obj))
|
||||||
|
addr, displayname = obj.addr, obj.name
|
||||||
|
elif isinstance(obj, str):
|
||||||
|
displayname, addr = parseaddr(obj)
|
||||||
|
else:
|
||||||
|
raise TypeError("don't know how to create chat for %r" % (obj, ))
|
||||||
|
|
||||||
|
if name is None and displayname:
|
||||||
|
name = displayname
|
||||||
|
return self._create_contact(addr, name)
|
||||||
|
|
||||||
|
def _create_contact(self, addr, name):
|
||||||
|
addr = as_dc_charpointer(addr)
|
||||||
name = as_dc_charpointer(name)
|
name = as_dc_charpointer(name)
|
||||||
email = as_dc_charpointer(email)
|
contact_id = lib.dc_create_contact(self._dc_context, name, addr)
|
||||||
contact_id = lib.dc_create_contact(self._dc_context, name, email)
|
assert contact_id > const.DC_CHAT_ID_LAST_SPECIAL, contact_id
|
||||||
assert contact_id > const.DC_CHAT_ID_LAST_SPECIAL
|
return Contact(self, contact_id)
|
||||||
return Contact(self._dc_context, contact_id)
|
|
||||||
|
|
||||||
def delete_contact(self, contact):
|
def delete_contact(self, contact):
|
||||||
""" delete a Contact.
|
""" delete a Contact.
|
||||||
@@ -165,10 +256,25 @@ class Account(object):
|
|||||||
:returns: True if deletion succeeded (contact was deleted)
|
:returns: True if deletion succeeded (contact was deleted)
|
||||||
"""
|
"""
|
||||||
contact_id = contact.id
|
contact_id = contact.id
|
||||||
assert contact._dc_context == self._dc_context
|
assert contact.account == self
|
||||||
assert contact_id > const.DC_CHAT_ID_LAST_SPECIAL
|
assert contact_id > const.DC_CHAT_ID_LAST_SPECIAL
|
||||||
return bool(lib.dc_delete_contact(self._dc_context, contact_id))
|
return bool(lib.dc_delete_contact(self._dc_context, contact_id))
|
||||||
|
|
||||||
|
def get_contact_by_addr(self, email):
|
||||||
|
""" get a contact for the email address or None if it's blocked or doesn't exist. """
|
||||||
|
_, addr = parseaddr(email)
|
||||||
|
addr = as_dc_charpointer(addr)
|
||||||
|
contact_id = lib.dc_lookup_contact_id_by_addr(self._dc_context, addr)
|
||||||
|
if contact_id:
|
||||||
|
return self.get_contact_by_id(contact_id)
|
||||||
|
|
||||||
|
def get_contact_by_id(self, contact_id):
|
||||||
|
""" return Contact instance or None.
|
||||||
|
:param contact_id: integer id of this contact.
|
||||||
|
:returns: None or :class:`deltachat.contact.Contact` instance.
|
||||||
|
"""
|
||||||
|
return Contact(self, contact_id)
|
||||||
|
|
||||||
def get_contacts(self, query=None, with_self=False, only_verified=False):
|
def get_contacts(self, query=None, with_self=False, only_verified=False):
|
||||||
""" get a (filtered) list of contacts.
|
""" get a (filtered) list of contacts.
|
||||||
|
|
||||||
@@ -176,7 +282,7 @@ class Account(object):
|
|||||||
whose name or e-mail matches query.
|
whose name or e-mail matches query.
|
||||||
:param only_verified: if true only return verified contacts.
|
:param only_verified: if true only return verified contacts.
|
||||||
:param with_self: if true the self-contact is also returned.
|
:param with_self: if true the self-contact is also returned.
|
||||||
:returns: list of :class:`deltachat.chatting.Contact` objects.
|
:returns: list of :class:`deltachat.contact.Contact` objects.
|
||||||
"""
|
"""
|
||||||
flags = 0
|
flags = 0
|
||||||
query = as_dc_charpointer(query)
|
query = as_dc_charpointer(query)
|
||||||
@@ -188,57 +294,44 @@ class Account(object):
|
|||||||
lib.dc_get_contacts(self._dc_context, flags, query),
|
lib.dc_get_contacts(self._dc_context, flags, query),
|
||||||
lib.dc_array_unref
|
lib.dc_array_unref
|
||||||
)
|
)
|
||||||
return list(iter_array(dc_array, lambda x: Contact(self._dc_context, x)))
|
return list(iter_array(dc_array, lambda x: Contact(self, x)))
|
||||||
|
|
||||||
def create_chat_by_contact(self, contact):
|
def get_fresh_messages(self):
|
||||||
""" create or get an existing 1:1 chat object for the specified contact or contact id.
|
""" yield all fresh messages from all chats. """
|
||||||
|
dc_array = ffi.gc(
|
||||||
|
lib.dc_get_fresh_msgs(self._dc_context),
|
||||||
|
lib.dc_array_unref
|
||||||
|
)
|
||||||
|
yield from iter_array(dc_array, lambda x: Message.from_db(self, x))
|
||||||
|
|
||||||
:param contact: chat_id (int) or contact object.
|
def create_chat(self, obj):
|
||||||
:returns: a :class:`deltachat.chatting.Chat` object.
|
""" Create a 1:1 chat with Account, Contact or e-mail address. """
|
||||||
"""
|
return self.create_contact(obj).create_chat()
|
||||||
if hasattr(contact, "id"):
|
|
||||||
if contact._dc_context != self._dc_context:
|
|
||||||
raise ValueError("Contact belongs to a different Account")
|
|
||||||
contact_id = contact.id
|
|
||||||
else:
|
|
||||||
assert isinstance(contact, int)
|
|
||||||
contact_id = contact
|
|
||||||
chat_id = lib.dc_create_chat_by_contact_id(self._dc_context, contact_id)
|
|
||||||
return Chat(self, chat_id)
|
|
||||||
|
|
||||||
def create_chat_by_message(self, message):
|
def _create_chat_by_message_id(self, msg_id):
|
||||||
""" create or get an existing chat object for the
|
return Chat(self, lib.dc_create_chat_by_msg_id(self._dc_context, msg_id))
|
||||||
the specified message.
|
|
||||||
|
|
||||||
:param message: messsage id or message instance.
|
def create_group_chat(self, name, contacts=None, verified=False):
|
||||||
:returns: a :class:`deltachat.chatting.Chat` object.
|
|
||||||
"""
|
|
||||||
if hasattr(message, "id"):
|
|
||||||
if self._dc_context != message._dc_context:
|
|
||||||
raise ValueError("Message belongs to a different Account")
|
|
||||||
msg_id = message.id
|
|
||||||
else:
|
|
||||||
assert isinstance(message, int)
|
|
||||||
msg_id = message
|
|
||||||
chat_id = lib.dc_create_chat_by_msg_id(self._dc_context, msg_id)
|
|
||||||
return Chat(self, chat_id)
|
|
||||||
|
|
||||||
def create_group_chat(self, name, verified=False):
|
|
||||||
""" create a new group chat object.
|
""" create a new group chat object.
|
||||||
|
|
||||||
Chats are unpromoted until the first message is sent.
|
Chats are unpromoted until the first message is sent.
|
||||||
|
|
||||||
|
:param contacts: list of contacts to add
|
||||||
:param verified: if true only verified contacts can be added.
|
:param verified: if true only verified contacts can be added.
|
||||||
:returns: a :class:`deltachat.chatting.Chat` object.
|
:returns: a :class:`deltachat.chat.Chat` object.
|
||||||
"""
|
"""
|
||||||
bytes_name = name.encode("utf8")
|
bytes_name = name.encode("utf8")
|
||||||
chat_id = lib.dc_create_group_chat(self._dc_context, verified, bytes_name)
|
chat_id = lib.dc_create_group_chat(self._dc_context, int(verified), bytes_name)
|
||||||
return Chat(self, chat_id)
|
chat = Chat(self, chat_id)
|
||||||
|
if contacts is not None:
|
||||||
|
for contact in contacts:
|
||||||
|
chat.add_contact(contact)
|
||||||
|
return chat
|
||||||
|
|
||||||
def get_chats(self):
|
def get_chats(self):
|
||||||
""" return list of chats.
|
""" return list of chats.
|
||||||
|
|
||||||
:returns: a list of :class:`deltachat.chatting.Chat` objects.
|
:returns: a list of :class:`deltachat.chat.Chat` objects.
|
||||||
"""
|
"""
|
||||||
dc_chatlist = ffi.gc(
|
dc_chatlist = ffi.gc(
|
||||||
lib.dc_get_chatlist(self._dc_context, 0, ffi.NULL, 0),
|
lib.dc_get_chatlist(self._dc_context, 0, ffi.NULL, 0),
|
||||||
@@ -256,9 +349,24 @@ class Account(object):
|
|||||||
return Chat(self, const.DC_CHAT_ID_DEADDROP)
|
return Chat(self, const.DC_CHAT_ID_DEADDROP)
|
||||||
|
|
||||||
def get_message_by_id(self, msg_id):
|
def get_message_by_id(self, msg_id):
|
||||||
""" return Message instance. """
|
""" return Message instance.
|
||||||
|
:param msg_id: integer id of this message.
|
||||||
|
:returns: :class:`deltachat.message.Message` instance.
|
||||||
|
"""
|
||||||
return Message.from_db(self, msg_id)
|
return Message.from_db(self, msg_id)
|
||||||
|
|
||||||
|
def get_chat_by_id(self, chat_id):
|
||||||
|
""" return Chat instance.
|
||||||
|
:param chat_id: integer id of this chat.
|
||||||
|
:returns: :class:`deltachat.chat.Chat` instance.
|
||||||
|
:raises: ValueError if chat does not exist.
|
||||||
|
"""
|
||||||
|
res = lib.dc_get_chat(self._dc_context, chat_id)
|
||||||
|
if res == ffi.NULL:
|
||||||
|
raise ValueError("cannot get chat with id={}".format(chat_id))
|
||||||
|
lib.dc_chat_unref(res)
|
||||||
|
return Chat(self, chat_id)
|
||||||
|
|
||||||
def mark_seen_messages(self, messages):
|
def mark_seen_messages(self, messages):
|
||||||
""" mark the given set of messages as seen.
|
""" mark the given set of messages as seen.
|
||||||
|
|
||||||
@@ -275,7 +383,7 @@ class Account(object):
|
|||||||
""" Forward list of messages to a chat.
|
""" Forward list of messages to a chat.
|
||||||
|
|
||||||
:param messages: list of :class:`deltachat.message.Message` object.
|
:param messages: list of :class:`deltachat.message.Message` object.
|
||||||
:param chat: :class:`deltachat.chatting.Chat` object.
|
:param chat: :class:`deltachat.chat.Chat` object.
|
||||||
:returns: None
|
:returns: None
|
||||||
"""
|
"""
|
||||||
msg_ids = [msg.id for msg in messages]
|
msg_ids = [msg.id for msg in messages]
|
||||||
@@ -290,31 +398,51 @@ class Account(object):
|
|||||||
msg_ids = [msg.id for msg in messages]
|
msg_ids = [msg.id for msg in messages]
|
||||||
lib.dc_delete_msgs(self._dc_context, msg_ids, len(msg_ids))
|
lib.dc_delete_msgs(self._dc_context, msg_ids, len(msg_ids))
|
||||||
|
|
||||||
def export_to_dir(self, backupdir):
|
def export_self_keys(self, path):
|
||||||
"""return after all delta chat state is exported to a new file in
|
""" export public and private keys to the specified directory.
|
||||||
the specified directory.
|
|
||||||
"""
|
|
||||||
snap_files = os.listdir(backupdir)
|
|
||||||
self._imex_completed.clear()
|
|
||||||
lib.dc_imex(self._dc_context, 11, as_dc_charpointer(backupdir), ffi.NULL)
|
|
||||||
if not self._threads.is_started():
|
|
||||||
lib.dc_perform_imap_jobs(self._dc_context)
|
|
||||||
self._imex_completed.wait()
|
|
||||||
for x in os.listdir(backupdir):
|
|
||||||
if x not in snap_files:
|
|
||||||
return os.path.join(backupdir, x)
|
|
||||||
|
|
||||||
def import_from_file(self, path):
|
Note that the account does not have to be started.
|
||||||
"""import delta chat state from the specified backup file.
|
"""
|
||||||
|
return self._export(path, imex_cmd=1)
|
||||||
|
|
||||||
|
def export_all(self, path):
|
||||||
|
"""return new file containing a backup of all database state
|
||||||
|
(chats, contacts, keys, media, ...). The file is created in the
|
||||||
|
the `path` directory.
|
||||||
|
|
||||||
|
Note that the account does not have to be started.
|
||||||
|
"""
|
||||||
|
export_files = self._export(path, 11)
|
||||||
|
if len(export_files) != 1:
|
||||||
|
raise RuntimeError("found more than one new file")
|
||||||
|
return export_files[0]
|
||||||
|
|
||||||
|
def _export(self, path, imex_cmd):
|
||||||
|
with self.temp_plugin(ImexTracker()) as imex_tracker:
|
||||||
|
lib.dc_imex(self._dc_context, imex_cmd, as_dc_charpointer(path), ffi.NULL)
|
||||||
|
return imex_tracker.wait_finish()
|
||||||
|
|
||||||
|
def import_self_keys(self, path):
|
||||||
|
""" Import private keys found in the `path` directory.
|
||||||
|
The last imported key is made the default keys unless its name
|
||||||
|
contains the string legacy. Public keys are not imported.
|
||||||
|
|
||||||
|
Note that the account does not have to be started.
|
||||||
|
"""
|
||||||
|
self._import(path, imex_cmd=2)
|
||||||
|
|
||||||
|
def import_all(self, path):
|
||||||
|
"""import delta chat state from the specified backup `path` (a file).
|
||||||
|
|
||||||
The account must be in unconfigured state for import to attempted.
|
The account must be in unconfigured state for import to attempted.
|
||||||
"""
|
"""
|
||||||
assert not self.is_configured(), "cannot import into configured account"
|
assert not self.is_configured(), "cannot import into configured account"
|
||||||
self._imex_completed.clear()
|
self._import(path, imex_cmd=12)
|
||||||
lib.dc_imex(self._dc_context, 12, as_dc_charpointer(path), ffi.NULL)
|
|
||||||
if not self._threads.is_started():
|
def _import(self, path, imex_cmd):
|
||||||
lib.dc_perform_imap_jobs(self._dc_context)
|
with self.temp_plugin(ImexTracker()) as imex_tracker:
|
||||||
self._imex_completed.wait()
|
lib.dc_imex(self._dc_context, imex_cmd, as_dc_charpointer(path), ffi.NULL)
|
||||||
|
imex_tracker.wait_finish()
|
||||||
|
|
||||||
def initiate_key_transfer(self):
|
def initiate_key_transfer(self):
|
||||||
"""return setup code after a Autocrypt setup message
|
"""return setup code after a Autocrypt setup message
|
||||||
@@ -322,173 +450,187 @@ class Account(object):
|
|||||||
If sending out was unsuccessful, a RuntimeError is raised.
|
If sending out was unsuccessful, a RuntimeError is raised.
|
||||||
"""
|
"""
|
||||||
self.check_is_configured()
|
self.check_is_configured()
|
||||||
if not self._threads.is_started():
|
if not self.is_started():
|
||||||
raise RuntimeError("threads not running, can not send out")
|
raise RuntimeError("IO not running, can not send out")
|
||||||
res = lib.dc_initiate_key_transfer(self._dc_context)
|
res = lib.dc_initiate_key_transfer(self._dc_context)
|
||||||
if res == ffi.NULL:
|
if res == ffi.NULL:
|
||||||
raise RuntimeError("could not send out autocrypt setup message")
|
raise RuntimeError("could not send out autocrypt setup message")
|
||||||
return from_dc_charpointer(res)
|
return from_dc_charpointer(res)
|
||||||
|
|
||||||
def start_threads(self):
|
def get_setup_contact_qr(self):
|
||||||
""" start IMAP/SMTP threads (and configure account if it hasn't happened).
|
""" get/create Setup-Contact QR Code as ascii-string.
|
||||||
|
|
||||||
|
this string needs to be transferred to another DC account
|
||||||
|
in a second channel (typically used by mobiles with QRcode-show + scan UX)
|
||||||
|
where qr_setup_contact(qr) is called.
|
||||||
|
"""
|
||||||
|
res = lib.dc_get_securejoin_qr(self._dc_context, 0)
|
||||||
|
return from_dc_charpointer(res)
|
||||||
|
|
||||||
|
def check_qr(self, qr):
|
||||||
|
""" check qr code and return :class:`ScannedQRCode` instance representing the result"""
|
||||||
|
res = ffi.gc(
|
||||||
|
lib.dc_check_qr(self._dc_context, as_dc_charpointer(qr)),
|
||||||
|
lib.dc_lot_unref
|
||||||
|
)
|
||||||
|
lot = DCLot(res)
|
||||||
|
if lot.state() == const.DC_QR_ERROR:
|
||||||
|
raise ValueError("invalid or unknown QR code: {}".format(lot.text1()))
|
||||||
|
return ScannedQRCode(lot)
|
||||||
|
|
||||||
|
def qr_setup_contact(self, qr):
|
||||||
|
""" setup contact and return a Chat after contact is established.
|
||||||
|
|
||||||
|
Note that this function may block for a long time as messages are exchanged
|
||||||
|
with the emitter of the QR code. On success a :class:`deltachat.chat.Chat` instance
|
||||||
|
is returned.
|
||||||
|
:param qr: valid "setup contact" QR code (all other QR codes will result in an exception)
|
||||||
|
"""
|
||||||
|
assert self.check_qr(qr).is_ask_verifycontact()
|
||||||
|
chat_id = lib.dc_join_securejoin(self._dc_context, as_dc_charpointer(qr))
|
||||||
|
if chat_id == 0:
|
||||||
|
raise ValueError("could not setup secure contact")
|
||||||
|
return Chat(self, chat_id)
|
||||||
|
|
||||||
|
def qr_join_chat(self, qr):
|
||||||
|
""" join a chat group through a QR code.
|
||||||
|
|
||||||
|
Note that this function may block for a long time as messages are exchanged
|
||||||
|
with the emitter of the QR code. On success a :class:`deltachat.chat.Chat` instance
|
||||||
|
is returned which is the chat that we just joined.
|
||||||
|
|
||||||
|
:param qr: valid "join-group" QR code (all other QR codes will result in an exception)
|
||||||
|
"""
|
||||||
|
assert self.check_qr(qr).is_ask_verifygroup()
|
||||||
|
chat_id = lib.dc_join_securejoin(self._dc_context, as_dc_charpointer(qr))
|
||||||
|
if chat_id == 0:
|
||||||
|
raise ValueError("could not join group")
|
||||||
|
return Chat(self, chat_id)
|
||||||
|
|
||||||
|
def set_location(self, latitude=0.0, longitude=0.0, accuracy=0.0):
|
||||||
|
"""set a new location. It effects all chats where we currently
|
||||||
|
have enabled location streaming.
|
||||||
|
|
||||||
|
:param latitude: float (use 0.0 if not known)
|
||||||
|
:param longitude: float (use 0.0 if not known)
|
||||||
|
:param accuracy: float (use 0.0 if not known)
|
||||||
|
:raises: ValueError if no chat is currently streaming locations
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
dc_res = lib.dc_set_location(self._dc_context, latitude, longitude, accuracy)
|
||||||
|
if dc_res == 0:
|
||||||
|
raise ValueError("no chat is streaming locations")
|
||||||
|
|
||||||
|
#
|
||||||
|
# meta API for start/stop and event based processing
|
||||||
|
#
|
||||||
|
|
||||||
|
def add_account_plugin(self, plugin, name=None):
|
||||||
|
""" add an account plugin which implements one or more of
|
||||||
|
the :class:`deltachat.hookspec.PerAccount` hooks.
|
||||||
|
"""
|
||||||
|
self._pm.register(plugin, name=name)
|
||||||
|
self._pm.check_pending()
|
||||||
|
return plugin
|
||||||
|
|
||||||
|
def remove_account_plugin(self, plugin, name=None):
|
||||||
|
""" remove an account plugin. """
|
||||||
|
self._pm.unregister(plugin, name=name)
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def temp_plugin(self, plugin):
|
||||||
|
""" run a with-block with the given plugin temporarily registered. """
|
||||||
|
self._pm.register(plugin)
|
||||||
|
yield plugin
|
||||||
|
self._pm.unregister(plugin)
|
||||||
|
|
||||||
|
def stop_ongoing(self):
|
||||||
|
""" Stop ongoing securejoin, configuration or other core jobs. """
|
||||||
|
lib.dc_stop_ongoing_process(self._dc_context)
|
||||||
|
|
||||||
|
def start_io(self):
|
||||||
|
""" start this account's IO scheduling (Rust-core async scheduler)
|
||||||
|
|
||||||
|
If this account is not configured an Exception is raised.
|
||||||
|
You need to call account.configure() and account.wait_configure_finish()
|
||||||
|
before.
|
||||||
|
|
||||||
|
You may call `stop_scheduler`, `wait_shutdown` or `shutdown` after the
|
||||||
|
account is started.
|
||||||
|
|
||||||
|
:raises MissingCredentials: if `addr` and `mail_pw` values are not set.
|
||||||
|
:raises ConfigureFailed: if the account could not be configured.
|
||||||
|
|
||||||
:raises: ValueError if 'addr' or 'mail_pw' are not configured.
|
|
||||||
:returns: None
|
:returns: None
|
||||||
"""
|
"""
|
||||||
if not self.is_configured():
|
if not self.is_configured():
|
||||||
self.configure()
|
raise ValueError("account not configured, cannot start io")
|
||||||
self._threads.start()
|
lib.dc_start_io(self._dc_context)
|
||||||
|
|
||||||
def stop_threads(self, wait=True):
|
def configure(self):
|
||||||
""" stop IMAP/SMTP threads. """
|
""" Start configuration process and return a Configtracker instance
|
||||||
lib.dc_stop_ongoing_process(self._dc_context)
|
on which you can block with wait_finish() to get a True/False success
|
||||||
self._threads.stop(wait=wait)
|
value for the configuration process.
|
||||||
|
"""
|
||||||
def shutdown(self, wait=True):
|
assert not self.is_configured()
|
||||||
""" stop threads and close and remove underlying dc_context and callbacks. """
|
if not self.get_config("addr") or not self.get_config("mail_pw"):
|
||||||
if hasattr(self, "_dc_context") and hasattr(self, "_threads"):
|
raise MissingCredentials("addr or mail_pwd not set in config")
|
||||||
self.stop_threads(wait=False) # to interrupt idle and tell python threads to stop
|
configtracker = ConfigureTracker(self)
|
||||||
lib.dc_close(self._dc_context)
|
self.add_account_plugin(configtracker)
|
||||||
self.stop_threads(wait=wait) # to wait for threads
|
lib.dc_configure(self._dc_context)
|
||||||
deltachat.clear_context_callback(self._dc_context)
|
return configtracker
|
||||||
del self._dc_context
|
|
||||||
|
|
||||||
def _process_event(self, ctx, evt_name, data1, data2):
|
|
||||||
assert ctx == self._dc_context
|
|
||||||
if hasattr(self, "_evlogger"):
|
|
||||||
self._evlogger(evt_name, data1, data2)
|
|
||||||
method = getattr(self, "on_" + evt_name.lower(), None)
|
|
||||||
if method is not None:
|
|
||||||
method(data1, data2)
|
|
||||||
return 0
|
|
||||||
|
|
||||||
def on_dc_event_imex_progress(self, data1, data2):
|
|
||||||
if data1 == 1000:
|
|
||||||
self._imex_completed.set()
|
|
||||||
|
|
||||||
|
|
||||||
class IOThreads:
|
|
||||||
def __init__(self, dc_context, log_event=lambda *args: None):
|
|
||||||
self._dc_context = dc_context
|
|
||||||
self._thread_quitflag = False
|
|
||||||
self._name2thread = {}
|
|
||||||
self._log_event = log_event
|
|
||||||
|
|
||||||
def is_started(self):
|
def is_started(self):
|
||||||
return len(self._name2thread) > 0
|
return self._event_thread.is_alive() and bool(lib.dc_is_io_running(self._dc_context))
|
||||||
|
|
||||||
def start(self, imap=True, smtp=True):
|
def wait_shutdown(self):
|
||||||
assert not self.is_started()
|
""" wait until shutdown of this account has completed. """
|
||||||
if imap:
|
self._shutdown_event.wait()
|
||||||
self._start_one_thread("imap", self.imap_thread_run)
|
|
||||||
if smtp:
|
|
||||||
self._start_one_thread("smtp", self.smtp_thread_run)
|
|
||||||
|
|
||||||
def _start_one_thread(self, name, func):
|
def stop_io(self):
|
||||||
self._name2thread[name] = t = threading.Thread(target=func, name=name)
|
""" stop core IO scheduler if it is running. """
|
||||||
t.setDaemon(1)
|
self.log("stop_ongoing")
|
||||||
t.start()
|
self.stop_ongoing()
|
||||||
|
|
||||||
def stop(self, wait=False):
|
if bool(lib.dc_is_io_running(self._dc_context)):
|
||||||
self._thread_quitflag = True
|
self.log("dc_stop_io (stop core IO scheduler)")
|
||||||
lib.dc_interrupt_imap_idle(self._dc_context)
|
lib.dc_stop_io(self._dc_context)
|
||||||
lib.dc_interrupt_smtp_idle(self._dc_context)
|
|
||||||
if wait:
|
|
||||||
for name, thread in self._name2thread.items():
|
|
||||||
thread.join()
|
|
||||||
|
|
||||||
def imap_thread_run(self):
|
|
||||||
self._log_event("py-bindings-info", 0, "IMAP THREAD START")
|
|
||||||
while not self._thread_quitflag:
|
|
||||||
lib.dc_perform_imap_jobs(self._dc_context)
|
|
||||||
lib.dc_perform_imap_fetch(self._dc_context)
|
|
||||||
lib.dc_perform_imap_idle(self._dc_context)
|
|
||||||
self._log_event("py-bindings-info", 0, "IMAP THREAD FINISHED")
|
|
||||||
|
|
||||||
def smtp_thread_run(self):
|
|
||||||
self._log_event("py-bindings-info", 0, "SMTP THREAD START")
|
|
||||||
while not self._thread_quitflag:
|
|
||||||
lib.dc_perform_smtp_jobs(self._dc_context)
|
|
||||||
lib.dc_perform_smtp_idle(self._dc_context)
|
|
||||||
self._log_event("py-bindings-info", 0, "SMTP THREAD FINISHED")
|
|
||||||
|
|
||||||
|
|
||||||
class EventLogger:
|
|
||||||
_loglock = threading.RLock()
|
|
||||||
|
|
||||||
def __init__(self, dc_context, logid=None, debug=True):
|
|
||||||
self._dc_context = dc_context
|
|
||||||
self._event_queue = Queue()
|
|
||||||
self._debug = debug
|
|
||||||
if logid is None:
|
|
||||||
logid = str(self._dc_context).strip(">").split()[-1]
|
|
||||||
self.logid = logid
|
|
||||||
self._timeout = None
|
|
||||||
self.init_time = time.time()
|
|
||||||
|
|
||||||
def __call__(self, evt_name, data1, data2):
|
|
||||||
self._log_event(evt_name, data1, data2)
|
|
||||||
self._event_queue.put((evt_name, data1, data2))
|
|
||||||
|
|
||||||
def set_timeout(self, timeout):
|
|
||||||
self._timeout = timeout
|
|
||||||
|
|
||||||
def get(self, timeout=None, check_error=True):
|
|
||||||
timeout = timeout or self._timeout
|
|
||||||
ev = self._event_queue.get(timeout=timeout)
|
|
||||||
if check_error and ev[0] == "DC_EVENT_ERROR":
|
|
||||||
raise ValueError("{}({!r},{!r})".format(*ev))
|
|
||||||
return ev
|
|
||||||
|
|
||||||
def ensure_event_not_queued(self, event_name_regex):
|
|
||||||
__tracebackhide__ = True
|
|
||||||
rex = re.compile("(?:{}).*".format(event_name_regex))
|
|
||||||
while 1:
|
|
||||||
try:
|
|
||||||
ev = self._event_queue.get(False)
|
|
||||||
except Empty:
|
|
||||||
break
|
|
||||||
else:
|
else:
|
||||||
assert not rex.match(ev[0]), "event found {}".format(ev)
|
self.log("stop_scheduler called on non-running context")
|
||||||
|
|
||||||
def get_matching(self, event_name_regex, check_error=True):
|
def shutdown(self):
|
||||||
self._log("-- waiting for event with regex: {} --".format(event_name_regex))
|
""" shutdown and destroy account (stop callback thread, close and remove
|
||||||
rex = re.compile("(?:{}).*".format(event_name_regex))
|
underlying dc_context)."""
|
||||||
while 1:
|
if self._dc_context is None:
|
||||||
ev = self.get()
|
|
||||||
if rex.match(ev[0]):
|
|
||||||
return ev
|
|
||||||
|
|
||||||
def get_info_matching(self, regex):
|
|
||||||
rex = re.compile("(?:{}).*".format(regex))
|
|
||||||
while 1:
|
|
||||||
ev = self.get_matching("DC_EVENT_INFO")
|
|
||||||
if rex.match(ev[2]):
|
|
||||||
return ev
|
|
||||||
|
|
||||||
def _log_event(self, evt_name, data1, data2):
|
|
||||||
# don't show events that are anyway empty impls now
|
|
||||||
if evt_name == "DC_EVENT_GET_STRING":
|
|
||||||
return
|
return
|
||||||
if self._debug:
|
|
||||||
evpart = "{}({!r},{!r})".format(evt_name, data1, data2)
|
|
||||||
self._log(evpart)
|
|
||||||
|
|
||||||
def _log(self, msg):
|
self.stop_io()
|
||||||
t = threading.currentThread()
|
|
||||||
tname = getattr(t, "name", t)
|
self.log("remove dc_context references")
|
||||||
if tname == "MainThread":
|
# the dc_context_unref triggers get_next_event to return ffi.NULL
|
||||||
tname = "MAIN"
|
# which in turns makes the event thread finish execution
|
||||||
with self._loglock:
|
self._dc_context = None
|
||||||
print("{:2.2f} [{}-{}] {}".format(time.time() - self.init_time, tname, self.logid, msg))
|
|
||||||
|
self.log("wait for event thread to finish")
|
||||||
|
self._event_thread.wait()
|
||||||
|
|
||||||
|
self._shutdown_event.set()
|
||||||
|
|
||||||
|
hook = hookspec.Global._get_plugin_manager().hook
|
||||||
|
hook.dc_account_after_shutdown(account=self)
|
||||||
|
self.log("shutdown finished")
|
||||||
|
|
||||||
|
|
||||||
def _destroy_dc_context(dc_context, dc_context_unref=lib.dc_context_unref):
|
class ScannedQRCode:
|
||||||
# destructor for dc_context
|
def __init__(self, dc_lot):
|
||||||
dc_context_unref(dc_context)
|
self._dc_lot = dc_lot
|
||||||
try:
|
|
||||||
deltachat.clear_context_callback(dc_context)
|
def is_ask_verifycontact(self):
|
||||||
except (TypeError, AttributeError):
|
return self._dc_lot.state() == const.DC_QR_ASK_VERIFYCONTACT
|
||||||
# we are deep into Python Interpreter shutdown,
|
|
||||||
# so no need to clear the callback context mapping.
|
def is_ask_verifygroup(self):
|
||||||
pass
|
return self._dc_lot.state() == const.DC_QR_ASK_VERIFYGROUP
|
||||||
|
|
||||||
|
@property
|
||||||
|
def contact_id(self):
|
||||||
|
return self._dc_lot.id()
|
||||||
|
|||||||
491
python/src/deltachat/chat.py
Normal file
@@ -0,0 +1,491 @@
|
|||||||
|
""" Chat and Location related API. """
|
||||||
|
|
||||||
|
import mimetypes
|
||||||
|
import calendar
|
||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
import os
|
||||||
|
from .cutil import as_dc_charpointer, from_dc_charpointer, iter_array
|
||||||
|
from .capi import lib, ffi
|
||||||
|
from . import const
|
||||||
|
from .message import Message
|
||||||
|
|
||||||
|
|
||||||
|
class Chat(object):
|
||||||
|
""" Chat object which manages members and through which you can send and retrieve messages.
|
||||||
|
|
||||||
|
You obtain instances of it through :class:`deltachat.account.Account`.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, account, id):
|
||||||
|
from .account import Account
|
||||||
|
assert isinstance(account, Account), repr(account)
|
||||||
|
self.account = account
|
||||||
|
self.id = id
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self.id == getattr(other, "id", None) and \
|
||||||
|
self.account._dc_context == other.account._dc_context
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return not (self == other)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "<Chat id={} name={}>".format(self.id, self.get_name())
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _dc_chat(self):
|
||||||
|
return ffi.gc(
|
||||||
|
lib.dc_get_chat(self.account._dc_context, self.id),
|
||||||
|
lib.dc_chat_unref
|
||||||
|
)
|
||||||
|
|
||||||
|
def delete(self):
|
||||||
|
"""Delete this chat and all its messages.
|
||||||
|
|
||||||
|
Note:
|
||||||
|
|
||||||
|
- does not delete messages on server
|
||||||
|
- the chat or contact is not blocked, new message will arrive
|
||||||
|
"""
|
||||||
|
lib.dc_delete_chat(self.account._dc_context, self.id)
|
||||||
|
|
||||||
|
# ------ chat status/metadata API ------------------------------
|
||||||
|
|
||||||
|
def is_group(self):
|
||||||
|
""" return true if this chat is a group chat.
|
||||||
|
|
||||||
|
:returns: True if chat is a group-chat, false if it's a contact 1:1 chat.
|
||||||
|
"""
|
||||||
|
return lib.dc_chat_get_type(self._dc_chat) in (
|
||||||
|
const.DC_CHAT_TYPE_GROUP,
|
||||||
|
const.DC_CHAT_TYPE_VERIFIED_GROUP
|
||||||
|
)
|
||||||
|
|
||||||
|
def is_deaddrop(self):
|
||||||
|
""" return true if this chat is a deaddrop chat.
|
||||||
|
|
||||||
|
:returns: True if chat is the deaddrop chat, False otherwise.
|
||||||
|
"""
|
||||||
|
return self.id == const.DC_CHAT_ID_DEADDROP
|
||||||
|
|
||||||
|
def is_muted(self):
|
||||||
|
""" return true if this chat is muted.
|
||||||
|
|
||||||
|
:returns: True if chat is muted, False otherwise.
|
||||||
|
"""
|
||||||
|
return lib.dc_chat_is_muted(self._dc_chat)
|
||||||
|
|
||||||
|
def is_promoted(self):
|
||||||
|
""" return True if this chat is promoted, i.e.
|
||||||
|
the member contacts are aware of their membership,
|
||||||
|
have been sent messages.
|
||||||
|
|
||||||
|
:returns: True if chat is promoted, False otherwise.
|
||||||
|
"""
|
||||||
|
return not lib.dc_chat_is_unpromoted(self._dc_chat)
|
||||||
|
|
||||||
|
def is_verified(self):
|
||||||
|
""" return True if this chat is a verified group.
|
||||||
|
|
||||||
|
:returns: True if chat is verified, False otherwise.
|
||||||
|
"""
|
||||||
|
return lib.dc_chat_is_verified(self._dc_chat)
|
||||||
|
|
||||||
|
def get_name(self):
|
||||||
|
""" return name of this chat.
|
||||||
|
|
||||||
|
:returns: unicode name
|
||||||
|
"""
|
||||||
|
return from_dc_charpointer(lib.dc_chat_get_name(self._dc_chat))
|
||||||
|
|
||||||
|
def set_name(self, name):
|
||||||
|
""" set name of this chat.
|
||||||
|
|
||||||
|
:param name: as a unicode string.
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
name = as_dc_charpointer(name)
|
||||||
|
return lib.dc_set_chat_name(self.account._dc_context, self.id, name)
|
||||||
|
|
||||||
|
def mute(self, duration=None):
|
||||||
|
""" mutes the chat
|
||||||
|
|
||||||
|
:param duration: Number of seconds to mute the chat for. None to mute until unmuted again.
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
if duration is None:
|
||||||
|
mute_duration = -1
|
||||||
|
else:
|
||||||
|
mute_duration = duration
|
||||||
|
ret = lib.dc_set_chat_mute_duration(self.account._dc_context, self.id, mute_duration)
|
||||||
|
if not bool(ret):
|
||||||
|
raise ValueError("Call to dc_set_chat_mute_duration failed")
|
||||||
|
|
||||||
|
def unmute(self):
|
||||||
|
""" unmutes the chat
|
||||||
|
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
ret = lib.dc_set_chat_mute_duration(self.account._dc_context, self.id, 0)
|
||||||
|
if not bool(ret):
|
||||||
|
raise ValueError("Failed to unmute chat")
|
||||||
|
|
||||||
|
def get_mute_duration(self):
|
||||||
|
""" Returns the number of seconds until the mute of this chat is lifted.
|
||||||
|
|
||||||
|
:param duration:
|
||||||
|
:returns: Returns the number of seconds the chat is still muted for. (0 for not muted, -1 forever muted)
|
||||||
|
"""
|
||||||
|
return bool(lib.dc_chat_get_remaining_mute_duration(self.id))
|
||||||
|
|
||||||
|
def get_type(self):
|
||||||
|
""" (deprecated) return type of this chat.
|
||||||
|
|
||||||
|
:returns: one of const.DC_CHAT_TYPE_*
|
||||||
|
"""
|
||||||
|
return lib.dc_chat_get_type(self._dc_chat)
|
||||||
|
|
||||||
|
def get_join_qr(self):
|
||||||
|
""" get/create Join-Group QR Code as ascii-string.
|
||||||
|
|
||||||
|
this string needs to be transferred to another DC account
|
||||||
|
in a second channel (typically used by mobiles with QRcode-show + scan UX)
|
||||||
|
where account.join_with_qrcode(qr) needs to be called.
|
||||||
|
"""
|
||||||
|
res = lib.dc_get_securejoin_qr(self.account._dc_context, self.id)
|
||||||
|
return from_dc_charpointer(res)
|
||||||
|
|
||||||
|
# ------ chat messaging API ------------------------------
|
||||||
|
|
||||||
|
def send_msg(self, msg):
|
||||||
|
"""send a message by using a ready Message object.
|
||||||
|
|
||||||
|
:param msg: a :class:`deltachat.message.Message` instance
|
||||||
|
previously returned by
|
||||||
|
e.g. :meth:`deltachat.message.Message.new_empty` or
|
||||||
|
:meth:`prepare_file`.
|
||||||
|
:raises ValueError: if message can not be sent.
|
||||||
|
|
||||||
|
:returns: a :class:`deltachat.message.Message` instance as
|
||||||
|
sent out. This is the same object as was passed in, which
|
||||||
|
has been modified with the new state of the core.
|
||||||
|
"""
|
||||||
|
if msg.is_out_preparing():
|
||||||
|
assert msg.id != 0
|
||||||
|
# get a fresh copy of dc_msg, the core needs it
|
||||||
|
msg = Message.from_db(self.account, msg.id)
|
||||||
|
sent_id = lib.dc_send_msg(self.account._dc_context, self.id, msg._dc_msg)
|
||||||
|
if sent_id == 0:
|
||||||
|
raise ValueError("message could not be sent")
|
||||||
|
# modify message in place to avoid bad state for the caller
|
||||||
|
msg._dc_msg = Message.from_db(self.account, sent_id)._dc_msg
|
||||||
|
return msg
|
||||||
|
|
||||||
|
def send_text(self, text):
|
||||||
|
""" send a text message and return the resulting Message instance.
|
||||||
|
|
||||||
|
:param msg: unicode text
|
||||||
|
:raises ValueError: if message can not be send/chat does not exist.
|
||||||
|
:returns: the resulting :class:`deltachat.message.Message` instance
|
||||||
|
"""
|
||||||
|
msg = as_dc_charpointer(text)
|
||||||
|
msg_id = lib.dc_send_text_msg(self.account._dc_context, self.id, msg)
|
||||||
|
if msg_id == 0:
|
||||||
|
raise ValueError("message could not be send, does chat exist?")
|
||||||
|
return Message.from_db(self.account, msg_id)
|
||||||
|
|
||||||
|
def send_file(self, path, mime_type="application/octet-stream"):
|
||||||
|
""" send a file and return the resulting Message instance.
|
||||||
|
|
||||||
|
:param path: path to the file.
|
||||||
|
:param mime_type: the mime-type of this file, defaults to application/octet-stream.
|
||||||
|
:raises ValueError: if message can not be send/chat does not exist.
|
||||||
|
:returns: the resulting :class:`deltachat.message.Message` instance
|
||||||
|
"""
|
||||||
|
msg = Message.new_empty(self.account, view_type="file")
|
||||||
|
msg.set_file(path, mime_type)
|
||||||
|
sent_id = lib.dc_send_msg(self.account._dc_context, self.id, msg._dc_msg)
|
||||||
|
if sent_id == 0:
|
||||||
|
raise ValueError("message could not be sent")
|
||||||
|
return Message.from_db(self.account, sent_id)
|
||||||
|
|
||||||
|
def send_image(self, path):
|
||||||
|
""" send an image message and return the resulting Message instance.
|
||||||
|
|
||||||
|
:param path: path to an image file.
|
||||||
|
:raises ValueError: if message can not be send/chat does not exist.
|
||||||
|
:returns: the resulting :class:`deltachat.message.Message` instance
|
||||||
|
"""
|
||||||
|
mime_type = mimetypes.guess_type(path)[0]
|
||||||
|
msg = Message.new_empty(self.account, view_type="image")
|
||||||
|
msg.set_file(path, mime_type)
|
||||||
|
sent_id = lib.dc_send_msg(self.account._dc_context, self.id, msg._dc_msg)
|
||||||
|
if sent_id == 0:
|
||||||
|
raise ValueError("message could not be sent")
|
||||||
|
return Message.from_db(self.account, sent_id)
|
||||||
|
|
||||||
|
def prepare_message(self, msg):
|
||||||
|
""" create a new prepared message.
|
||||||
|
|
||||||
|
:param msg: the message to be prepared.
|
||||||
|
:returns: :class:`deltachat.message.Message` instance.
|
||||||
|
"""
|
||||||
|
msg_id = lib.dc_prepare_msg(self.account._dc_context, self.id, msg._dc_msg)
|
||||||
|
if msg_id == 0:
|
||||||
|
raise ValueError("message could not be prepared")
|
||||||
|
# invalidate passed in message which is not safe to use anymore
|
||||||
|
msg._dc_msg = msg.id = None
|
||||||
|
return Message.from_db(self.account, msg_id)
|
||||||
|
|
||||||
|
def prepare_message_file(self, path, mime_type=None, view_type="file"):
|
||||||
|
""" prepare a message for sending and return the resulting Message instance.
|
||||||
|
|
||||||
|
To actually send the message, call :meth:`send_prepared`.
|
||||||
|
The file must be inside the blob directory.
|
||||||
|
|
||||||
|
:param path: path to the file.
|
||||||
|
:param mime_type: the mime-type of this file, defaults to auto-detection.
|
||||||
|
:param view_type: "text", "image", "gif", "audio", "video", "file"
|
||||||
|
:raises ValueError: if message can not be prepared/chat does not exist.
|
||||||
|
:returns: the resulting :class:`Message` instance
|
||||||
|
"""
|
||||||
|
msg = Message.new_empty(self.account, view_type)
|
||||||
|
msg.set_file(path, mime_type)
|
||||||
|
return self.prepare_message(msg)
|
||||||
|
|
||||||
|
def send_prepared(self, message):
|
||||||
|
""" send a previously prepared message.
|
||||||
|
|
||||||
|
:param message: a :class:`Message` instance previously returned by
|
||||||
|
:meth:`prepare_file`.
|
||||||
|
:raises ValueError: if message can not be sent.
|
||||||
|
:returns: a :class:`deltachat.message.Message` instance as sent out.
|
||||||
|
"""
|
||||||
|
assert message.id != 0 and message.is_out_preparing()
|
||||||
|
# get a fresh copy of dc_msg, the core needs it
|
||||||
|
msg = Message.from_db(self.account, message.id)
|
||||||
|
|
||||||
|
# pass 0 as chat-id because core-docs say it's ok when out-preparing
|
||||||
|
sent_id = lib.dc_send_msg(self.account._dc_context, 0, msg._dc_msg)
|
||||||
|
if sent_id == 0:
|
||||||
|
raise ValueError("message could not be sent")
|
||||||
|
assert sent_id == msg.id
|
||||||
|
# modify message in place to avoid bad state for the caller
|
||||||
|
msg._dc_msg = Message.from_db(self.account, sent_id)._dc_msg
|
||||||
|
|
||||||
|
def set_draft(self, message):
|
||||||
|
""" set message as draft.
|
||||||
|
|
||||||
|
:param message: a :class:`Message` instance
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
if message is None:
|
||||||
|
lib.dc_set_draft(self.account._dc_context, self.id, ffi.NULL)
|
||||||
|
else:
|
||||||
|
lib.dc_set_draft(self.account._dc_context, self.id, message._dc_msg)
|
||||||
|
|
||||||
|
def get_draft(self):
|
||||||
|
""" get draft message for this chat.
|
||||||
|
|
||||||
|
:param message: a :class:`Message` instance
|
||||||
|
:returns: Message object or None (if no draft available)
|
||||||
|
"""
|
||||||
|
x = lib.dc_get_draft(self.account._dc_context, self.id)
|
||||||
|
if x == ffi.NULL:
|
||||||
|
return None
|
||||||
|
dc_msg = ffi.gc(x, lib.dc_msg_unref)
|
||||||
|
return Message(self.account, dc_msg)
|
||||||
|
|
||||||
|
def get_messages(self):
|
||||||
|
""" return list of messages in this chat.
|
||||||
|
|
||||||
|
:returns: list of :class:`deltachat.message.Message` objects for this chat.
|
||||||
|
"""
|
||||||
|
dc_array = ffi.gc(
|
||||||
|
lib.dc_get_chat_msgs(self.account._dc_context, self.id, 0, 0),
|
||||||
|
lib.dc_array_unref
|
||||||
|
)
|
||||||
|
return list(iter_array(dc_array, lambda x: Message.from_db(self.account, x)))
|
||||||
|
|
||||||
|
def count_fresh_messages(self):
|
||||||
|
""" return number of fresh messages in this chat.
|
||||||
|
|
||||||
|
:returns: number of fresh messages
|
||||||
|
"""
|
||||||
|
return lib.dc_get_fresh_msg_cnt(self.account._dc_context, self.id)
|
||||||
|
|
||||||
|
def mark_noticed(self):
|
||||||
|
""" mark all messages in this chat as noticed.
|
||||||
|
|
||||||
|
Noticed messages are no longer fresh.
|
||||||
|
"""
|
||||||
|
return lib.dc_marknoticed_chat(self.account._dc_context, self.id)
|
||||||
|
|
||||||
|
def get_summary(self):
|
||||||
|
""" return dictionary with summary information. """
|
||||||
|
dc_res = lib.dc_chat_get_info_json(self.account._dc_context, self.id)
|
||||||
|
s = from_dc_charpointer(dc_res)
|
||||||
|
return json.loads(s)
|
||||||
|
|
||||||
|
# ------ group management API ------------------------------
|
||||||
|
|
||||||
|
def add_contact(self, obj):
|
||||||
|
""" add a contact to this chat.
|
||||||
|
|
||||||
|
:params obj: Contact, Account or e-mail address.
|
||||||
|
:raises ValueError: if contact could not be added
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
contact = self.account.create_contact(obj)
|
||||||
|
ret = lib.dc_add_contact_to_chat(self.account._dc_context, self.id, contact.id)
|
||||||
|
if ret != 1:
|
||||||
|
raise ValueError("could not add contact {!r} to chat".format(contact))
|
||||||
|
return contact
|
||||||
|
|
||||||
|
def remove_contact(self, obj):
|
||||||
|
""" remove a contact from this chat.
|
||||||
|
|
||||||
|
:params obj: Contact, Account or e-mail address.
|
||||||
|
:raises ValueError: if contact could not be removed
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
contact = self.account.create_contact(obj)
|
||||||
|
ret = lib.dc_remove_contact_from_chat(self.account._dc_context, self.id, contact.id)
|
||||||
|
if ret != 1:
|
||||||
|
raise ValueError("could not remove contact {!r} from chat".format(contact))
|
||||||
|
|
||||||
|
def get_contacts(self):
|
||||||
|
""" get all contacts for this chat.
|
||||||
|
:returns: list of :class:`deltachat.contact.Contact` objects for this chat
|
||||||
|
"""
|
||||||
|
from .contact import Contact
|
||||||
|
dc_array = ffi.gc(
|
||||||
|
lib.dc_get_chat_contacts(self.account._dc_context, self.id),
|
||||||
|
lib.dc_array_unref
|
||||||
|
)
|
||||||
|
return list(iter_array(
|
||||||
|
dc_array, lambda id: Contact(self.account, id))
|
||||||
|
)
|
||||||
|
|
||||||
|
def num_contacts(self):
|
||||||
|
""" return number of contacts in this chat. """
|
||||||
|
dc_array = ffi.gc(
|
||||||
|
lib.dc_get_chat_contacts(self.account._dc_context, self.id),
|
||||||
|
lib.dc_array_unref
|
||||||
|
)
|
||||||
|
return lib.dc_array_get_cnt(dc_array)
|
||||||
|
|
||||||
|
def set_profile_image(self, img_path):
|
||||||
|
"""Set group profile image.
|
||||||
|
|
||||||
|
If the group is already promoted (any message was sent to the group),
|
||||||
|
all group members are informed by a special status message that is sent
|
||||||
|
automatically by this function.
|
||||||
|
:params img_path: path to image object
|
||||||
|
:raises ValueError: if profile image could not be set
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
assert os.path.exists(img_path), img_path
|
||||||
|
p = as_dc_charpointer(img_path)
|
||||||
|
res = lib.dc_set_chat_profile_image(self.account._dc_context, self.id, p)
|
||||||
|
if res != 1:
|
||||||
|
raise ValueError("Setting Profile Image {!r} failed".format(p))
|
||||||
|
|
||||||
|
def remove_profile_image(self):
|
||||||
|
"""remove group profile image.
|
||||||
|
|
||||||
|
If the group is already promoted (any message was sent to the group),
|
||||||
|
all group members are informed by a special status message that is sent
|
||||||
|
automatically by this function.
|
||||||
|
:raises ValueError: if profile image could not be reset
|
||||||
|
:returns: None
|
||||||
|
"""
|
||||||
|
res = lib.dc_set_chat_profile_image(self.account._dc_context, self.id, ffi.NULL)
|
||||||
|
if res != 1:
|
||||||
|
raise ValueError("Removing Profile Image failed")
|
||||||
|
|
||||||
|
def get_profile_image(self):
|
||||||
|
"""Get group profile image.
|
||||||
|
|
||||||
|
For groups, this is the image set by any group member using
|
||||||
|
set_chat_profile_image(). For normal chats, this is the image
|
||||||
|
set by each remote user on their own using dc_set_config(context,
|
||||||
|
"selfavatar", image).
|
||||||
|
:returns: path to profile image, None if no profile image exists.
|
||||||
|
"""
|
||||||
|
dc_res = lib.dc_chat_get_profile_image(self._dc_chat)
|
||||||
|
if dc_res == ffi.NULL:
|
||||||
|
return None
|
||||||
|
return from_dc_charpointer(dc_res)
|
||||||
|
|
||||||
|
def get_color(self):
|
||||||
|
"""return the color of the chat.
|
||||||
|
:returns: color as 0x00rrggbb
|
||||||
|
"""
|
||||||
|
return lib.dc_chat_get_color(self._dc_chat)
|
||||||
|
|
||||||
|
# ------ location streaming API ------------------------------
|
||||||
|
|
||||||
|
def is_sending_locations(self):
|
||||||
|
"""return True if this chat has location-sending enabled currently.
|
||||||
|
:returns: True if location sending is enabled.
|
||||||
|
"""
|
||||||
|
return lib.dc_is_sending_locations_to_chat(self.account._dc_context, self.id)
|
||||||
|
|
||||||
|
def is_archived(self):
|
||||||
|
"""return True if this chat is archived.
|
||||||
|
:returns: True if archived.
|
||||||
|
"""
|
||||||
|
return lib.dc_chat_get_visibility(self._dc_chat) == const.DC_CHAT_VISIBILITY_ARCHIVED
|
||||||
|
|
||||||
|
def enable_sending_locations(self, seconds):
|
||||||
|
"""enable sending locations for this chat.
|
||||||
|
|
||||||
|
all subsequent messages will carry a location with them.
|
||||||
|
"""
|
||||||
|
lib.dc_send_locations_to_chat(self.account._dc_context, self.id, seconds)
|
||||||
|
|
||||||
|
def get_locations(self, contact=None, timestamp_from=None, timestamp_to=None):
|
||||||
|
"""return list of locations for the given contact in the given timespan.
|
||||||
|
|
||||||
|
:param contact: the contact for which locations shall be returned.
|
||||||
|
:param timespan_from: a datetime object or None (indicating "since beginning")
|
||||||
|
:param timespan_to: a datetime object or None (indicating up till now)
|
||||||
|
:returns: list of :class:`deltachat.chat.Location` objects.
|
||||||
|
"""
|
||||||
|
if timestamp_from is None:
|
||||||
|
time_from = 0
|
||||||
|
else:
|
||||||
|
time_from = calendar.timegm(timestamp_from.utctimetuple())
|
||||||
|
if timestamp_to is None:
|
||||||
|
time_to = 0
|
||||||
|
else:
|
||||||
|
time_to = calendar.timegm(timestamp_to.utctimetuple())
|
||||||
|
|
||||||
|
if contact is None:
|
||||||
|
contact_id = 0
|
||||||
|
else:
|
||||||
|
contact_id = contact.id
|
||||||
|
|
||||||
|
dc_array = lib.dc_get_locations(self.account._dc_context, self.id, contact_id, time_from, time_to)
|
||||||
|
return [
|
||||||
|
Location(
|
||||||
|
latitude=lib.dc_array_get_latitude(dc_array, i),
|
||||||
|
longitude=lib.dc_array_get_longitude(dc_array, i),
|
||||||
|
accuracy=lib.dc_array_get_accuracy(dc_array, i),
|
||||||
|
timestamp=datetime.utcfromtimestamp(lib.dc_array_get_timestamp(dc_array, i)))
|
||||||
|
for i in range(lib.dc_array_get_cnt(dc_array))
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class Location:
|
||||||
|
def __init__(self, latitude, longitude, accuracy, timestamp):
|
||||||
|
assert isinstance(timestamp, datetime)
|
||||||
|
self.latitude = latitude
|
||||||
|
self.longitude = longitude
|
||||||
|
self.accuracy = accuracy
|
||||||
|
self.timestamp = timestamp
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self.__dict__ == other.__dict__
|
||||||
@@ -1,307 +0,0 @@
|
|||||||
""" chatting related objects: Contact, Chat, Message. """
|
|
||||||
|
|
||||||
import mimetypes
|
|
||||||
from . import props
|
|
||||||
from .cutil import as_dc_charpointer, from_dc_charpointer, iter_array
|
|
||||||
from .capi import lib, ffi
|
|
||||||
from . import const
|
|
||||||
from .message import Message
|
|
||||||
|
|
||||||
|
|
||||||
class Contact(object):
|
|
||||||
""" Delta-Chat Contact.
|
|
||||||
|
|
||||||
You obtain instances of it through :class:`deltachat.account.Account`.
|
|
||||||
"""
|
|
||||||
def __init__(self, dc_context, id):
|
|
||||||
self._dc_context = dc_context
|
|
||||||
self.id = id
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
return self._dc_context == other._dc_context and self.id == other.id
|
|
||||||
|
|
||||||
def __ne__(self, other):
|
|
||||||
return not (self == other)
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return "<Contact id={} addr={} dc_context={}>".format(self.id, self.addr, self._dc_context)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def _dc_contact(self):
|
|
||||||
return ffi.gc(
|
|
||||||
lib.dc_get_contact(self._dc_context, self.id),
|
|
||||||
lib.dc_contact_unref
|
|
||||||
)
|
|
||||||
|
|
||||||
@props.with_doc
|
|
||||||
def addr(self):
|
|
||||||
""" normalized e-mail address for this account. """
|
|
||||||
return from_dc_charpointer(lib.dc_contact_get_addr(self._dc_contact))
|
|
||||||
|
|
||||||
@props.with_doc
|
|
||||||
def display_name(self):
|
|
||||||
""" display name for this contact. """
|
|
||||||
return from_dc_charpointer(lib.dc_contact_get_display_name(self._dc_contact))
|
|
||||||
|
|
||||||
def is_blocked(self):
|
|
||||||
""" Return True if the contact is blocked. """
|
|
||||||
return lib.dc_contact_is_blocked(self._dc_contact)
|
|
||||||
|
|
||||||
def is_verified(self):
|
|
||||||
""" Return True if the contact is verified. """
|
|
||||||
return lib.dc_contact_is_verified(self._dc_contact)
|
|
||||||
|
|
||||||
|
|
||||||
class Chat(object):
|
|
||||||
""" Chat object which manages members and through which you can send and retrieve messages.
|
|
||||||
|
|
||||||
You obtain instances of it through :class:`deltachat.account.Account`.
|
|
||||||
"""
|
|
||||||
|
|
||||||
def __init__(self, account, id):
|
|
||||||
self.account = account
|
|
||||||
self._dc_context = account._dc_context
|
|
||||||
self.id = id
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
return self.id == getattr(other, "id", None) and \
|
|
||||||
self._dc_context == getattr(other, "_dc_context", None)
|
|
||||||
|
|
||||||
def __ne__(self, other):
|
|
||||||
return not (self == other)
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return "<Chat id={} name={} dc_context={}>".format(self.id, self.get_name(), self._dc_context)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def _dc_chat(self):
|
|
||||||
return ffi.gc(
|
|
||||||
lib.dc_get_chat(self._dc_context, self.id),
|
|
||||||
lib.dc_chat_unref
|
|
||||||
)
|
|
||||||
|
|
||||||
def delete(self):
|
|
||||||
"""Delete this chat and all its messages.
|
|
||||||
|
|
||||||
Note:
|
|
||||||
|
|
||||||
- does not delete messages on server
|
|
||||||
- the chat or contact is not blocked, new message will arrive
|
|
||||||
"""
|
|
||||||
lib.dc_delete_chat(self._dc_context, self.id)
|
|
||||||
|
|
||||||
# ------ chat status/metadata API ------------------------------
|
|
||||||
|
|
||||||
def is_deaddrop(self):
|
|
||||||
""" return true if this chat is a deaddrop chat.
|
|
||||||
|
|
||||||
:returns: True if chat is the deaddrop chat, False otherwise.
|
|
||||||
"""
|
|
||||||
return self.id == const.DC_CHAT_ID_DEADDROP
|
|
||||||
|
|
||||||
def is_promoted(self):
|
|
||||||
""" return True if this chat is promoted, i.e.
|
|
||||||
the member contacts are aware of their membership,
|
|
||||||
have been sent messages.
|
|
||||||
|
|
||||||
:returns: True if chat is promoted, False otherwise.
|
|
||||||
"""
|
|
||||||
return not lib.dc_chat_is_unpromoted(self._dc_chat)
|
|
||||||
|
|
||||||
def get_name(self):
|
|
||||||
""" return name of this chat.
|
|
||||||
|
|
||||||
:returns: unicode name
|
|
||||||
"""
|
|
||||||
return from_dc_charpointer(lib.dc_chat_get_name(self._dc_chat))
|
|
||||||
|
|
||||||
def set_name(self, name):
|
|
||||||
""" set name of this chat.
|
|
||||||
|
|
||||||
:param: name as a unicode string.
|
|
||||||
:returns: None
|
|
||||||
"""
|
|
||||||
name = as_dc_charpointer(name)
|
|
||||||
return lib.dc_set_chat_name(self._dc_context, self.id, name)
|
|
||||||
|
|
||||||
def get_type(self):
|
|
||||||
""" return type of this chat.
|
|
||||||
|
|
||||||
:returns: one of const.DC_CHAT_TYPE_*
|
|
||||||
"""
|
|
||||||
return lib.dc_chat_get_type(self._dc_chat)
|
|
||||||
|
|
||||||
# ------ chat messaging API ------------------------------
|
|
||||||
|
|
||||||
def send_text(self, text):
|
|
||||||
""" send a text message and return the resulting Message instance.
|
|
||||||
|
|
||||||
:param msg: unicode text
|
|
||||||
:raises ValueError: if message can not be send/chat does not exist.
|
|
||||||
:returns: the resulting :class:`deltachat.message.Message` instance
|
|
||||||
"""
|
|
||||||
msg = as_dc_charpointer(text)
|
|
||||||
msg_id = lib.dc_send_text_msg(self._dc_context, self.id, msg)
|
|
||||||
if msg_id == 0:
|
|
||||||
raise ValueError("message could not be send, does chat exist?")
|
|
||||||
return Message.from_db(self.account, msg_id)
|
|
||||||
|
|
||||||
def send_file(self, path, mime_type="application/octet-stream"):
|
|
||||||
""" send a file and return the resulting Message instance.
|
|
||||||
|
|
||||||
:param path: path to the file.
|
|
||||||
:param mime_type: the mime-type of this file, defaults to application/octet-stream.
|
|
||||||
:raises ValueError: if message can not be send/chat does not exist.
|
|
||||||
:returns: the resulting :class:`deltachat.message.Message` instance
|
|
||||||
"""
|
|
||||||
msg = self.prepare_message_file(path=path, mime_type=mime_type)
|
|
||||||
self.send_prepared(msg)
|
|
||||||
return msg
|
|
||||||
|
|
||||||
def send_image(self, path):
|
|
||||||
""" send an image message and return the resulting Message instance.
|
|
||||||
|
|
||||||
:param path: path to an image file.
|
|
||||||
:raises ValueError: if message can not be send/chat does not exist.
|
|
||||||
:returns: the resulting :class:`deltachat.message.Message` instance
|
|
||||||
"""
|
|
||||||
mime_type = mimetypes.guess_type(path)[0]
|
|
||||||
msg = self.prepare_message_file(path=path, mime_type=mime_type, view_type="image")
|
|
||||||
self.send_prepared(msg)
|
|
||||||
return msg
|
|
||||||
|
|
||||||
def prepare_message(self, msg):
|
|
||||||
""" create a new prepared message.
|
|
||||||
|
|
||||||
:param msg: the message to be prepared.
|
|
||||||
:returns: :class:`deltachat.message.Message` instance.
|
|
||||||
"""
|
|
||||||
msg_id = lib.dc_prepare_msg(self._dc_context, self.id, msg._dc_msg)
|
|
||||||
if msg_id == 0:
|
|
||||||
raise ValueError("message could not be prepared")
|
|
||||||
# invalidate passed in message which is not safe to use anymore
|
|
||||||
msg._dc_msg = msg.id = None
|
|
||||||
return Message.from_db(self.account, msg_id)
|
|
||||||
|
|
||||||
def prepare_message_file(self, path, mime_type=None, view_type="file"):
|
|
||||||
""" prepare a message for sending and return the resulting Message instance.
|
|
||||||
|
|
||||||
To actually send the message, call :meth:`send_prepared`.
|
|
||||||
The file must be inside the blob directory.
|
|
||||||
|
|
||||||
:param path: path to the file.
|
|
||||||
:param mime_type: the mime-type of this file, defaults to auto-detection.
|
|
||||||
:param view_type: "text", "image", "gif", "audio", "video", "file"
|
|
||||||
:raises ValueError: if message can not be prepared/chat does not exist.
|
|
||||||
:returns: the resulting :class:`Message` instance
|
|
||||||
"""
|
|
||||||
msg = Message.new_empty(self.account, view_type)
|
|
||||||
msg.set_file(path, mime_type)
|
|
||||||
return self.prepare_message(msg)
|
|
||||||
|
|
||||||
def send_prepared(self, message):
|
|
||||||
""" send a previously prepared message.
|
|
||||||
|
|
||||||
:param message: a :class:`Message` instance previously returned by
|
|
||||||
:meth:`prepare_file`.
|
|
||||||
:raises ValueError: if message can not be sent.
|
|
||||||
:returns: a :class:`deltachat.message.Message` instance as sent out.
|
|
||||||
"""
|
|
||||||
assert message.id != 0 and message.is_out_preparing()
|
|
||||||
# get a fresh copy of dc_msg, the core needs it
|
|
||||||
msg = Message.from_db(self.account, message.id)
|
|
||||||
|
|
||||||
# pass 0 as chat-id because core-docs say it's ok when out-preparing
|
|
||||||
sent_id = lib.dc_send_msg(self._dc_context, 0, msg._dc_msg)
|
|
||||||
if sent_id == 0:
|
|
||||||
raise ValueError("message could not be sent")
|
|
||||||
assert sent_id == msg.id
|
|
||||||
# modify message in place to avoid bad state for the caller
|
|
||||||
msg._dc_msg = Message.from_db(self.account, sent_id)._dc_msg
|
|
||||||
|
|
||||||
def set_draft(self, message):
|
|
||||||
""" set message as draft.
|
|
||||||
|
|
||||||
:param message: a :class:`Message` instance
|
|
||||||
:returns: None
|
|
||||||
"""
|
|
||||||
if message is None:
|
|
||||||
lib.dc_set_draft(self._dc_context, self.id, ffi.NULL)
|
|
||||||
else:
|
|
||||||
lib.dc_set_draft(self._dc_context, self.id, message._dc_msg)
|
|
||||||
|
|
||||||
def get_draft(self):
|
|
||||||
""" get draft message for this chat.
|
|
||||||
|
|
||||||
:param message: a :class:`Message` instance
|
|
||||||
:returns: Message object or None (if no draft available)
|
|
||||||
"""
|
|
||||||
x = lib.dc_get_draft(self._dc_context, self.id)
|
|
||||||
if x == ffi.NULL:
|
|
||||||
return None
|
|
||||||
dc_msg = ffi.gc(x, lib.dc_msg_unref)
|
|
||||||
return Message(self.account, dc_msg)
|
|
||||||
|
|
||||||
def get_messages(self):
|
|
||||||
""" return list of messages in this chat.
|
|
||||||
|
|
||||||
:returns: list of :class:`deltachat.message.Message` objects for this chat.
|
|
||||||
"""
|
|
||||||
dc_array = ffi.gc(
|
|
||||||
lib.dc_get_chat_msgs(self._dc_context, self.id, 0, 0),
|
|
||||||
lib.dc_array_unref
|
|
||||||
)
|
|
||||||
return list(iter_array(dc_array, lambda x: Message.from_db(self.account, x)))
|
|
||||||
|
|
||||||
def count_fresh_messages(self):
|
|
||||||
""" return number of fresh messages in this chat.
|
|
||||||
|
|
||||||
:returns: number of fresh messages
|
|
||||||
"""
|
|
||||||
return lib.dc_get_fresh_msg_cnt(self._dc_context, self.id)
|
|
||||||
|
|
||||||
def mark_noticed(self):
|
|
||||||
""" mark all messages in this chat as noticed.
|
|
||||||
|
|
||||||
Noticed messages are no longer fresh.
|
|
||||||
"""
|
|
||||||
return lib.dc_marknoticed_chat(self._dc_context, self.id)
|
|
||||||
|
|
||||||
# ------ group management API ------------------------------
|
|
||||||
|
|
||||||
def add_contact(self, contact):
|
|
||||||
""" add a contact to this chat.
|
|
||||||
|
|
||||||
:params: contact object.
|
|
||||||
:raises ValueError: if contact could not be added
|
|
||||||
:returns: None
|
|
||||||
"""
|
|
||||||
ret = lib.dc_add_contact_to_chat(self._dc_context, self.id, contact.id)
|
|
||||||
if ret != 1:
|
|
||||||
raise ValueError("could not add contact {!r} to chat".format(contact))
|
|
||||||
|
|
||||||
def remove_contact(self, contact):
|
|
||||||
""" remove a contact from this chat.
|
|
||||||
|
|
||||||
:params: contact object.
|
|
||||||
:raises ValueError: if contact could not be removed
|
|
||||||
:returns: None
|
|
||||||
"""
|
|
||||||
ret = lib.dc_remove_contact_from_chat(self._dc_context, self.id, contact.id)
|
|
||||||
if ret != 1:
|
|
||||||
raise ValueError("could not remove contact {!r} from chat".format(contact))
|
|
||||||
|
|
||||||
def get_contacts(self):
|
|
||||||
""" get all contacts for this chat.
|
|
||||||
:params: contact object.
|
|
||||||
:raises ValueError: if contact could not be added
|
|
||||||
:returns: list of :class:`deltachat.chatting.Contact` objects for this chat
|
|
||||||
|
|
||||||
"""
|
|
||||||
dc_array = ffi.gc(
|
|
||||||
lib.dc_get_chat_contacts(self._dc_context, self.id),
|
|
||||||
lib.dc_array_unref
|
|
||||||
)
|
|
||||||
return list(iter_array(
|
|
||||||
dc_array, lambda id: Contact(self._dc_context, id))
|
|
||||||
)
|
|
||||||
@@ -1,113 +1,7 @@
|
|||||||
import sys
|
from .capi import lib
|
||||||
import re
|
|
||||||
import os
|
|
||||||
from os.path import dirname, abspath
|
|
||||||
from os.path import join as joinpath
|
|
||||||
|
|
||||||
# the following const are generated from deltachat.h
|
|
||||||
# this works well when you in a git-checkout
|
|
||||||
# run "python deltachat/const.py" to regenerate events
|
|
||||||
# begin const generated
|
|
||||||
DC_GCL_ARCHIVED_ONLY = 0x01
|
|
||||||
DC_GCL_NO_SPECIALS = 0x02
|
|
||||||
DC_GCL_ADD_ALLDONE_HINT = 0x04
|
|
||||||
DC_GCL_VERIFIED_ONLY = 0x01
|
|
||||||
DC_GCL_ADD_SELF = 0x02
|
|
||||||
DC_CHAT_ID_DEADDROP = 1
|
|
||||||
DC_CHAT_ID_TRASH = 3
|
|
||||||
DC_CHAT_ID_MSGS_IN_CREATION = 4
|
|
||||||
DC_CHAT_ID_STARRED = 5
|
|
||||||
DC_CHAT_ID_ARCHIVED_LINK = 6
|
|
||||||
DC_CHAT_ID_ALLDONE_HINT = 7
|
|
||||||
DC_CHAT_ID_LAST_SPECIAL = 9
|
|
||||||
DC_CHAT_TYPE_UNDEFINED = 0
|
|
||||||
DC_CHAT_TYPE_SINGLE = 100
|
|
||||||
DC_CHAT_TYPE_GROUP = 120
|
|
||||||
DC_CHAT_TYPE_VERIFIED_GROUP = 130
|
|
||||||
DC_MSG_ID_MARKER1 = 1
|
|
||||||
DC_MSG_ID_DAYMARKER = 9
|
|
||||||
DC_MSG_ID_LAST_SPECIAL = 9
|
|
||||||
DC_STATE_UNDEFINED = 0
|
|
||||||
DC_STATE_IN_FRESH = 10
|
|
||||||
DC_STATE_IN_NOTICED = 13
|
|
||||||
DC_STATE_IN_SEEN = 16
|
|
||||||
DC_STATE_OUT_PREPARING = 18
|
|
||||||
DC_STATE_OUT_DRAFT = 19
|
|
||||||
DC_STATE_OUT_PENDING = 20
|
|
||||||
DC_STATE_OUT_FAILED = 24
|
|
||||||
DC_STATE_OUT_DELIVERED = 26
|
|
||||||
DC_STATE_OUT_MDN_RCVD = 28
|
|
||||||
DC_CONTACT_ID_SELF = 1
|
|
||||||
DC_CONTACT_ID_DEVICE = 2
|
|
||||||
DC_CONTACT_ID_LAST_SPECIAL = 9
|
|
||||||
DC_MSG_TEXT = 10
|
|
||||||
DC_MSG_IMAGE = 20
|
|
||||||
DC_MSG_GIF = 21
|
|
||||||
DC_MSG_AUDIO = 40
|
|
||||||
DC_MSG_VOICE = 41
|
|
||||||
DC_MSG_VIDEO = 50
|
|
||||||
DC_MSG_FILE = 60
|
|
||||||
DC_EVENT_INFO = 100
|
|
||||||
DC_EVENT_SMTP_CONNECTED = 101
|
|
||||||
DC_EVENT_IMAP_CONNECTED = 102
|
|
||||||
DC_EVENT_SMTP_MESSAGE_SENT = 103
|
|
||||||
DC_EVENT_WARNING = 300
|
|
||||||
DC_EVENT_ERROR = 400
|
|
||||||
DC_EVENT_ERROR_NETWORK = 401
|
|
||||||
DC_EVENT_ERROR_SELF_NOT_IN_GROUP = 410
|
|
||||||
DC_EVENT_MSGS_CHANGED = 2000
|
|
||||||
DC_EVENT_INCOMING_MSG = 2005
|
|
||||||
DC_EVENT_MSG_DELIVERED = 2010
|
|
||||||
DC_EVENT_MSG_FAILED = 2012
|
|
||||||
DC_EVENT_MSG_READ = 2015
|
|
||||||
DC_EVENT_CHAT_MODIFIED = 2020
|
|
||||||
DC_EVENT_CONTACTS_CHANGED = 2030
|
|
||||||
DC_EVENT_LOCATION_CHANGED = 2035
|
|
||||||
DC_EVENT_CONFIGURE_PROGRESS = 2041
|
|
||||||
DC_EVENT_IMEX_PROGRESS = 2051
|
|
||||||
DC_EVENT_IMEX_FILE_WRITTEN = 2052
|
|
||||||
DC_EVENT_SECUREJOIN_INVITER_PROGRESS = 2060
|
|
||||||
DC_EVENT_SECUREJOIN_JOINER_PROGRESS = 2061
|
|
||||||
DC_EVENT_GET_STRING = 2091
|
|
||||||
DC_EVENT_HTTP_GET = 2100
|
|
||||||
DC_EVENT_HTTP_POST = 2110
|
|
||||||
DC_EVENT_FILE_COPIED = 2055
|
|
||||||
DC_EVENT_IS_OFFLINE = 2081
|
|
||||||
# end const generated
|
|
||||||
|
|
||||||
|
|
||||||
def read_event_defines(f):
|
for name in dir(lib):
|
||||||
rex = re.compile(r'#define\s+((?:DC_EVENT_|DC_MSG|DC_STATE_|DC_CONTACT_ID_|DC_GCL|DC_CHAT)\S+)\s+([x\d]+).*')
|
if name.startswith("DC_"):
|
||||||
for line in f:
|
globals()[name] = getattr(lib, name)
|
||||||
m = rex.match(line)
|
del name
|
||||||
if m:
|
|
||||||
yield m.groups()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
here = abspath(__file__).rstrip("oc")
|
|
||||||
here_dir = dirname(here)
|
|
||||||
if len(sys.argv) >= 2:
|
|
||||||
deltah = sys.argv[1]
|
|
||||||
else:
|
|
||||||
deltah = joinpath(dirname(dirname(dirname(here_dir))), "src", "deltachat.h")
|
|
||||||
assert os.path.exists(deltah)
|
|
||||||
|
|
||||||
lines = []
|
|
||||||
skip_to_end = False
|
|
||||||
for orig_line in open(here):
|
|
||||||
if skip_to_end:
|
|
||||||
if not orig_line.startswith("# end const"):
|
|
||||||
continue
|
|
||||||
skip_to_end = False
|
|
||||||
lines.append(orig_line)
|
|
||||||
if orig_line.startswith("# begin const"):
|
|
||||||
with open(deltah) as f:
|
|
||||||
for name, item in read_event_defines(f):
|
|
||||||
lines.append("{} = {}\n".format(name, item))
|
|
||||||
skip_to_end = True
|
|
||||||
|
|
||||||
tmpname = here + ".tmp"
|
|
||||||
with open(tmpname, "w") as f:
|
|
||||||
f.write("".join(lines))
|
|
||||||
os.rename(tmpname, here)
|
|
||||||
|
|||||||
80
python/src/deltachat/contact.py
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
""" Contact object. """
|
||||||
|
|
||||||
|
from . import props
|
||||||
|
from .cutil import from_dc_charpointer
|
||||||
|
from .capi import lib, ffi
|
||||||
|
from .chat import Chat
|
||||||
|
from . import const
|
||||||
|
|
||||||
|
|
||||||
|
class Contact(object):
|
||||||
|
""" Delta-Chat Contact.
|
||||||
|
|
||||||
|
You obtain instances of it through :class:`deltachat.account.Account`.
|
||||||
|
"""
|
||||||
|
def __init__(self, account, id):
|
||||||
|
from .account import Account
|
||||||
|
assert isinstance(account, Account), repr(account)
|
||||||
|
self.account = account
|
||||||
|
self.id = id
|
||||||
|
|
||||||
|
def __eq__(self, other):
|
||||||
|
return self.account._dc_context == other.account._dc_context and self.id == other.id
|
||||||
|
|
||||||
|
def __ne__(self, other):
|
||||||
|
return not (self == other)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return "<Contact id={} addr={} dc_context={}>".format(self.id, self.addr, self.account._dc_context)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def _dc_contact(self):
|
||||||
|
return ffi.gc(
|
||||||
|
lib.dc_get_contact(self.account._dc_context, self.id),
|
||||||
|
lib.dc_contact_unref
|
||||||
|
)
|
||||||
|
|
||||||
|
@props.with_doc
|
||||||
|
def addr(self):
|
||||||
|
""" normalized e-mail address for this account. """
|
||||||
|
return from_dc_charpointer(lib.dc_contact_get_addr(self._dc_contact))
|
||||||
|
|
||||||
|
@props.with_doc
|
||||||
|
def name(self):
|
||||||
|
""" display name for this contact. """
|
||||||
|
return from_dc_charpointer(lib.dc_contact_get_display_name(self._dc_contact))
|
||||||
|
|
||||||
|
# deprecated alias
|
||||||
|
display_name = name
|
||||||
|
|
||||||
|
def is_blocked(self):
|
||||||
|
""" Return True if the contact is blocked. """
|
||||||
|
return lib.dc_contact_is_blocked(self._dc_contact)
|
||||||
|
|
||||||
|
def is_verified(self):
|
||||||
|
""" Return True if the contact is verified. """
|
||||||
|
return lib.dc_contact_is_verified(self._dc_contact)
|
||||||
|
|
||||||
|
def get_profile_image(self):
|
||||||
|
"""Get contact profile image.
|
||||||
|
|
||||||
|
:returns: path to profile image, None if no profile image exists.
|
||||||
|
"""
|
||||||
|
dc_res = lib.dc_contact_get_profile_image(self._dc_contact)
|
||||||
|
if dc_res == ffi.NULL:
|
||||||
|
return None
|
||||||
|
return from_dc_charpointer(dc_res)
|
||||||
|
|
||||||
|
def create_chat(self):
|
||||||
|
""" create or get an existing 1:1 chat object for the specified contact or contact id.
|
||||||
|
|
||||||
|
:param contact: chat_id (int) or contact object.
|
||||||
|
:returns: a :class:`deltachat.chat.Chat` object.
|
||||||
|
"""
|
||||||
|
dc_context = self.account._dc_context
|
||||||
|
chat_id = lib.dc_create_chat_by_contact_id(dc_context, self.id)
|
||||||
|
assert chat_id > const.DC_CHAT_ID_LAST_SPECIAL, chat_id
|
||||||
|
return Chat(self.account, chat_id)
|
||||||
|
|
||||||
|
# deprecated name
|
||||||
|
get_chat = create_chat
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
from .capi import lib
|
from .capi import lib
|
||||||
from .capi import ffi
|
from .capi import ffi
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
def as_dc_charpointer(obj):
|
def as_dc_charpointer(obj):
|
||||||
@@ -17,3 +18,29 @@ def iter_array(dc_array_t, constructor):
|
|||||||
|
|
||||||
def from_dc_charpointer(obj):
|
def from_dc_charpointer(obj):
|
||||||
return ffi.string(ffi.gc(obj, lib.dc_str_unref)).decode("utf8")
|
return ffi.string(ffi.gc(obj, lib.dc_str_unref)).decode("utf8")
|
||||||
|
|
||||||
|
|
||||||
|
class DCLot:
|
||||||
|
def __init__(self, dc_lot):
|
||||||
|
self._dc_lot = dc_lot
|
||||||
|
|
||||||
|
def id(self):
|
||||||
|
return lib.dc_lot_get_id(self._dc_lot)
|
||||||
|
|
||||||
|
def state(self):
|
||||||
|
return lib.dc_lot_get_state(self._dc_lot)
|
||||||
|
|
||||||
|
def text1(self):
|
||||||
|
return from_dc_charpointer(lib.dc_lot_get_text1(self._dc_lot))
|
||||||
|
|
||||||
|
def text1_meaning(self):
|
||||||
|
return lib.dc_lot_get_text1_meaning(self._dc_lot)
|
||||||
|
|
||||||
|
def text2(self):
|
||||||
|
return from_dc_charpointer(lib.dc_lot_get_text2(self._dc_lot))
|
||||||
|
|
||||||
|
def timestamp(self):
|
||||||
|
ts = lib.dc_lot_get_timestamp(self._dc_lot)
|
||||||
|
if ts == 0:
|
||||||
|
return None
|
||||||
|
return datetime.utcfromtimestamp(ts)
|
||||||
|
|||||||
213
python/src/deltachat/direct_imap.py
Normal file
@@ -0,0 +1,213 @@
|
|||||||
|
"""
|
||||||
|
Internal Python-level IMAP handling used by the testplugin
|
||||||
|
and for cleaning up inbox/mvbox for each test function run.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import io
|
||||||
|
import email
|
||||||
|
import ssl
|
||||||
|
import pathlib
|
||||||
|
from imapclient import IMAPClient
|
||||||
|
from imapclient.exceptions import IMAPClientError
|
||||||
|
import deltachat
|
||||||
|
|
||||||
|
|
||||||
|
SEEN = b'\\Seen'
|
||||||
|
DELETED = b'\\Deleted'
|
||||||
|
FLAGS = b'FLAGS'
|
||||||
|
FETCH = b'FETCH'
|
||||||
|
ALL = "1:*"
|
||||||
|
|
||||||
|
|
||||||
|
@deltachat.global_hookimpl
|
||||||
|
def dc_account_extra_configure(account):
|
||||||
|
""" Reset the account (we reuse accounts across tests)
|
||||||
|
and make 'account.direct_imap' available for direct IMAP ops.
|
||||||
|
"""
|
||||||
|
imap = DirectImap(account)
|
||||||
|
if imap.select_config_folder("mvbox"):
|
||||||
|
imap.delete(ALL, expunge=True)
|
||||||
|
assert imap.select_config_folder("inbox")
|
||||||
|
imap.delete(ALL, expunge=True)
|
||||||
|
setattr(account, "direct_imap", imap)
|
||||||
|
|
||||||
|
|
||||||
|
@deltachat.global_hookimpl
|
||||||
|
def dc_account_after_shutdown(account):
|
||||||
|
""" shutdown the imap connection if there is one. """
|
||||||
|
imap = getattr(account, "direct_imap", None)
|
||||||
|
if imap is not None:
|
||||||
|
imap.shutdown()
|
||||||
|
del account.direct_imap
|
||||||
|
|
||||||
|
|
||||||
|
class DirectImap:
|
||||||
|
def __init__(self, account):
|
||||||
|
self.account = account
|
||||||
|
self.logid = account.get_config("displayname") or id(account)
|
||||||
|
self._idling = False
|
||||||
|
self.connect()
|
||||||
|
|
||||||
|
def connect(self):
|
||||||
|
ssl_context = ssl.create_default_context()
|
||||||
|
|
||||||
|
# don't check if certificate hostname doesn't match target hostname
|
||||||
|
ssl_context.check_hostname = False
|
||||||
|
|
||||||
|
# don't check if the certificate is trusted by a certificate authority
|
||||||
|
ssl_context.verify_mode = ssl.CERT_NONE
|
||||||
|
|
||||||
|
host = self.account.get_config("configured_mail_server")
|
||||||
|
user = self.account.get_config("addr")
|
||||||
|
pw = self.account.get_config("mail_pw")
|
||||||
|
self.conn = IMAPClient(host, ssl_context=ssl_context)
|
||||||
|
self.conn.login(user, pw)
|
||||||
|
|
||||||
|
self.select_folder("INBOX")
|
||||||
|
|
||||||
|
def shutdown(self):
|
||||||
|
try:
|
||||||
|
self.conn.idle_done()
|
||||||
|
except (OSError, IMAPClientError):
|
||||||
|
pass
|
||||||
|
try:
|
||||||
|
self.conn.logout()
|
||||||
|
except (OSError, IMAPClientError):
|
||||||
|
print("Could not logout direct_imap conn")
|
||||||
|
|
||||||
|
def select_folder(self, foldername):
|
||||||
|
assert not self._idling
|
||||||
|
return self.conn.select_folder(foldername)
|
||||||
|
|
||||||
|
def select_config_folder(self, config_name):
|
||||||
|
""" Return info about selected folder if it is
|
||||||
|
configured, otherwise None. """
|
||||||
|
if "_" not in config_name:
|
||||||
|
config_name = "configured_{}_folder".format(config_name)
|
||||||
|
foldername = self.account.get_config(config_name)
|
||||||
|
if foldername:
|
||||||
|
return self.select_folder(foldername)
|
||||||
|
|
||||||
|
def list_folders(self):
|
||||||
|
""" return list of all existing folder names"""
|
||||||
|
assert not self._idling
|
||||||
|
folders = []
|
||||||
|
for meta, sep, foldername in self.conn.list_folders():
|
||||||
|
folders.append(foldername)
|
||||||
|
return folders
|
||||||
|
|
||||||
|
def delete(self, range, expunge=True):
|
||||||
|
""" delete a range of messages (imap-syntax).
|
||||||
|
If expunge is true, perform the expunge-operation
|
||||||
|
to make sure the messages are really gone and not
|
||||||
|
just flagged as deleted.
|
||||||
|
"""
|
||||||
|
self.conn.set_flags(range, [DELETED])
|
||||||
|
if expunge:
|
||||||
|
self.conn.expunge()
|
||||||
|
|
||||||
|
def get_all_messages(self):
|
||||||
|
assert not self._idling
|
||||||
|
return self.conn.fetch(ALL, [FLAGS])
|
||||||
|
|
||||||
|
def get_unread_messages(self):
|
||||||
|
assert not self._idling
|
||||||
|
res = self.conn.fetch(ALL, [FLAGS])
|
||||||
|
return [uid for uid in res
|
||||||
|
if SEEN not in res[uid][FLAGS]]
|
||||||
|
|
||||||
|
def mark_all_read(self):
|
||||||
|
messages = self.get_unread_messages()
|
||||||
|
if messages:
|
||||||
|
res = self.conn.set_flags(messages, [SEEN])
|
||||||
|
print("marked seen:", messages, res)
|
||||||
|
|
||||||
|
def get_unread_cnt(self):
|
||||||
|
return len(self.get_unread_messages())
|
||||||
|
|
||||||
|
def dump_account_info(self, logfile):
|
||||||
|
def log(*args, **kwargs):
|
||||||
|
kwargs["file"] = logfile
|
||||||
|
print(*args, **kwargs)
|
||||||
|
|
||||||
|
cursor = 0
|
||||||
|
for name, val in self.account.get_info().items():
|
||||||
|
entry = "{}={}".format(name.upper(), val)
|
||||||
|
if cursor + len(entry) > 80:
|
||||||
|
log("")
|
||||||
|
cursor = 0
|
||||||
|
log(entry, end=" ")
|
||||||
|
cursor += len(entry) + 1
|
||||||
|
log("")
|
||||||
|
|
||||||
|
def dump_imap_structures(self, dir, logfile):
|
||||||
|
assert not self._idling
|
||||||
|
stream = io.StringIO()
|
||||||
|
|
||||||
|
def log(*args, **kwargs):
|
||||||
|
kwargs["file"] = stream
|
||||||
|
print(*args, **kwargs)
|
||||||
|
|
||||||
|
empty_folders = []
|
||||||
|
for imapfolder in self.list_folders():
|
||||||
|
self.select_folder(imapfolder)
|
||||||
|
messages = list(self.get_all_messages())
|
||||||
|
if not messages:
|
||||||
|
empty_folders.append(imapfolder)
|
||||||
|
continue
|
||||||
|
|
||||||
|
log("---------", imapfolder, len(messages), "messages ---------")
|
||||||
|
# get message content without auto-marking it as seen
|
||||||
|
# fetching 'RFC822' would mark it as seen.
|
||||||
|
requested = [b'BODY.PEEK[HEADER]', FLAGS]
|
||||||
|
for uid, data in self.conn.fetch(messages, requested).items():
|
||||||
|
body_bytes = data[b'BODY[HEADER]']
|
||||||
|
flags = data[FLAGS]
|
||||||
|
path = pathlib.Path(str(dir)).joinpath("IMAP", self.logid, imapfolder)
|
||||||
|
path.mkdir(parents=True, exist_ok=True)
|
||||||
|
fn = path.joinpath(str(uid))
|
||||||
|
fn.write_bytes(body_bytes)
|
||||||
|
log("Message", uid, fn)
|
||||||
|
email_message = email.message_from_bytes(body_bytes)
|
||||||
|
log("Message", uid, flags, "Message-Id:", email_message.get("Message-Id"))
|
||||||
|
|
||||||
|
if empty_folders:
|
||||||
|
log("--------- EMPTY FOLDERS:", empty_folders)
|
||||||
|
|
||||||
|
print(stream.getvalue(), file=logfile)
|
||||||
|
|
||||||
|
def idle_start(self):
|
||||||
|
""" switch this connection to idle mode. non-blocking. """
|
||||||
|
assert not self._idling
|
||||||
|
res = self.conn.idle()
|
||||||
|
self._idling = True
|
||||||
|
return res
|
||||||
|
|
||||||
|
def idle_check(self, terminate=False):
|
||||||
|
""" (blocking) wait for next idle message from server. """
|
||||||
|
assert self._idling
|
||||||
|
self.account.log("imap-direct: calling idle_check")
|
||||||
|
res = self.conn.idle_check(timeout=30)
|
||||||
|
if len(res) == 0:
|
||||||
|
raise TimeoutError
|
||||||
|
if terminate:
|
||||||
|
self.idle_done()
|
||||||
|
return res
|
||||||
|
|
||||||
|
def idle_wait_for_seen(self):
|
||||||
|
""" Return first message with SEEN flag
|
||||||
|
from a running idle-stream REtiurn.
|
||||||
|
"""
|
||||||
|
while 1:
|
||||||
|
for item in self.idle_check():
|
||||||
|
if item[1] == FETCH:
|
||||||
|
if item[2][0] == FLAGS:
|
||||||
|
if SEEN in item[2][1]:
|
||||||
|
return item[0]
|
||||||
|
|
||||||
|
def idle_done(self):
|
||||||
|
""" send idle-done to server if we are currently in idle mode. """
|
||||||
|
if self._idling:
|
||||||
|
res = self.conn.idle_done()
|
||||||
|
self._idling = False
|
||||||
|
return res
|
||||||
219
python/src/deltachat/events.py
Normal file
@@ -0,0 +1,219 @@
|
|||||||
|
import threading
|
||||||
|
import time
|
||||||
|
import re
|
||||||
|
from queue import Queue, Empty
|
||||||
|
|
||||||
|
import deltachat
|
||||||
|
from .hookspec import account_hookimpl
|
||||||
|
from contextlib import contextmanager
|
||||||
|
from .capi import ffi, lib
|
||||||
|
from .message import map_system_message
|
||||||
|
from .cutil import from_dc_charpointer
|
||||||
|
|
||||||
|
|
||||||
|
class FFIEvent:
|
||||||
|
def __init__(self, name, data1, data2):
|
||||||
|
self.name = name
|
||||||
|
self.data1 = data1
|
||||||
|
self.data2 = data2
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return "{name} data1={data1} data2={data2}".format(**self.__dict__)
|
||||||
|
|
||||||
|
|
||||||
|
class FFIEventLogger:
|
||||||
|
""" If you register an instance of this logger with an Account
|
||||||
|
you'll get all ffi-events printed.
|
||||||
|
"""
|
||||||
|
# to prevent garbled logging
|
||||||
|
_loglock = threading.RLock()
|
||||||
|
|
||||||
|
def __init__(self, account):
|
||||||
|
self.account = account
|
||||||
|
self.logid = self.account.get_config("displayname")
|
||||||
|
self.init_time = time.time()
|
||||||
|
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_process_ffi_event(self, ffi_event):
|
||||||
|
self.account.log(str(ffi_event))
|
||||||
|
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_log_line(self, message):
|
||||||
|
t = threading.currentThread()
|
||||||
|
tname = getattr(t, "name", t)
|
||||||
|
if tname == "MainThread":
|
||||||
|
tname = "MAIN"
|
||||||
|
elapsed = time.time() - self.init_time
|
||||||
|
locname = tname
|
||||||
|
if self.logid:
|
||||||
|
locname += "-" + self.logid
|
||||||
|
s = "{:2.2f} [{}] {}".format(elapsed, locname, message)
|
||||||
|
with self._loglock:
|
||||||
|
print(s, flush=True)
|
||||||
|
|
||||||
|
|
||||||
|
class FFIEventTracker:
|
||||||
|
def __init__(self, account, timeout=None):
|
||||||
|
self.account = account
|
||||||
|
self._timeout = timeout
|
||||||
|
self._event_queue = Queue()
|
||||||
|
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_process_ffi_event(self, ffi_event):
|
||||||
|
self._event_queue.put(ffi_event)
|
||||||
|
|
||||||
|
def set_timeout(self, timeout):
|
||||||
|
self._timeout = timeout
|
||||||
|
|
||||||
|
def consume_events(self, check_error=True):
|
||||||
|
while not self._event_queue.empty():
|
||||||
|
self.get(check_error=check_error)
|
||||||
|
|
||||||
|
def get(self, timeout=None, check_error=True):
|
||||||
|
timeout = timeout if timeout is not None else self._timeout
|
||||||
|
ev = self._event_queue.get(timeout=timeout)
|
||||||
|
if check_error and ev.name == "DC_EVENT_ERROR":
|
||||||
|
raise ValueError("unexpected event: {}".format(ev))
|
||||||
|
return ev
|
||||||
|
|
||||||
|
def iter_events(self, timeout=None, check_error=True):
|
||||||
|
while 1:
|
||||||
|
yield self.get(timeout=timeout, check_error=check_error)
|
||||||
|
|
||||||
|
def get_matching(self, event_name_regex, check_error=True, timeout=None):
|
||||||
|
rex = re.compile("(?:{}).*".format(event_name_regex))
|
||||||
|
for ev in self.iter_events(timeout=timeout, check_error=check_error):
|
||||||
|
if rex.match(ev.name):
|
||||||
|
return ev
|
||||||
|
|
||||||
|
def get_info_matching(self, regex):
|
||||||
|
rex = re.compile("(?:{}).*".format(regex))
|
||||||
|
while 1:
|
||||||
|
ev = self.get_matching("DC_EVENT_INFO")
|
||||||
|
if rex.match(ev.data2):
|
||||||
|
return ev
|
||||||
|
|
||||||
|
def ensure_event_not_queued(self, event_name_regex):
|
||||||
|
__tracebackhide__ = True
|
||||||
|
rex = re.compile("(?:{}).*".format(event_name_regex))
|
||||||
|
while 1:
|
||||||
|
try:
|
||||||
|
ev = self._event_queue.get(False)
|
||||||
|
except Empty:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
assert not rex.match(ev.name), "event found {}".format(ev)
|
||||||
|
|
||||||
|
def wait_securejoin_inviter_progress(self, target):
|
||||||
|
while 1:
|
||||||
|
event = self.get_matching("DC_EVENT_SECUREJOIN_INVITER_PROGRESS")
|
||||||
|
if event.data2 >= target:
|
||||||
|
print("** SECUREJOINT-INVITER PROGRESS {}".format(target), self.account)
|
||||||
|
break
|
||||||
|
|
||||||
|
def wait_next_incoming_message(self):
|
||||||
|
""" wait for and return next incoming message. """
|
||||||
|
ev = self.get_matching("DC_EVENT_INCOMING_MSG")
|
||||||
|
return self.account.get_message_by_id(ev.data2)
|
||||||
|
|
||||||
|
def wait_next_messages_changed(self):
|
||||||
|
""" wait for and return next message-changed message or None
|
||||||
|
if the event contains no msgid"""
|
||||||
|
ev = self.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
|
if ev.data2 > 0:
|
||||||
|
return self.account.get_message_by_id(ev.data2)
|
||||||
|
|
||||||
|
def wait_msg_delivered(self, msg):
|
||||||
|
ev = self.get_matching("DC_EVENT_MSG_DELIVERED")
|
||||||
|
assert ev.data1 == msg.chat.id
|
||||||
|
assert ev.data2 == msg.id
|
||||||
|
assert msg.is_out_delivered()
|
||||||
|
|
||||||
|
|
||||||
|
class EventThread(threading.Thread):
|
||||||
|
""" Event Thread for an account.
|
||||||
|
|
||||||
|
With each Account init this callback thread is started.
|
||||||
|
"""
|
||||||
|
def __init__(self, account):
|
||||||
|
self.account = account
|
||||||
|
super(EventThread, self).__init__(name="events")
|
||||||
|
self.setDaemon(True)
|
||||||
|
self.start()
|
||||||
|
|
||||||
|
@contextmanager
|
||||||
|
def log_execution(self, message):
|
||||||
|
self.account.log(message + " START")
|
||||||
|
yield
|
||||||
|
self.account.log(message + " FINISHED")
|
||||||
|
|
||||||
|
def wait(self):
|
||||||
|
if self == threading.current_thread():
|
||||||
|
# we are in the callback thread and thus cannot
|
||||||
|
# wait for the thread-loop to finish.
|
||||||
|
return
|
||||||
|
self.join()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
""" get and run events until shutdown. """
|
||||||
|
with self.log_execution("EVENT THREAD"):
|
||||||
|
self._inner_run()
|
||||||
|
|
||||||
|
def _inner_run(self):
|
||||||
|
event_emitter = ffi.gc(
|
||||||
|
lib.dc_get_event_emitter(self.account._dc_context),
|
||||||
|
lib.dc_event_emitter_unref,
|
||||||
|
)
|
||||||
|
while 1:
|
||||||
|
event = lib.dc_get_next_event(event_emitter)
|
||||||
|
if event == ffi.NULL:
|
||||||
|
break
|
||||||
|
evt = lib.dc_event_get_id(event)
|
||||||
|
data1 = lib.dc_event_get_data1_int(event)
|
||||||
|
# the following code relates to the deltachat/_build.py's helper
|
||||||
|
# function which provides us signature info of an event call
|
||||||
|
evt_name = deltachat.get_dc_event_name(evt)
|
||||||
|
if lib.dc_event_has_string_data(evt):
|
||||||
|
data2 = from_dc_charpointer(lib.dc_event_get_data2_str(event))
|
||||||
|
else:
|
||||||
|
data2 = lib.dc_event_get_data2_int(event)
|
||||||
|
|
||||||
|
lib.dc_event_unref(event)
|
||||||
|
ffi_event = FFIEvent(name=evt_name, data1=data1, data2=data2)
|
||||||
|
try:
|
||||||
|
self.account._pm.hook.ac_process_ffi_event(account=self, ffi_event=ffi_event)
|
||||||
|
for name, kwargs in self._map_ffi_event(ffi_event):
|
||||||
|
self.account.log("calling hook name={} kwargs={}".format(name, kwargs))
|
||||||
|
hook = getattr(self.account._pm.hook, name)
|
||||||
|
hook(**kwargs)
|
||||||
|
except Exception:
|
||||||
|
if self.account._dc_context is not None:
|
||||||
|
raise
|
||||||
|
|
||||||
|
def _map_ffi_event(self, ffi_event):
|
||||||
|
name = ffi_event.name
|
||||||
|
account = self.account
|
||||||
|
if name == "DC_EVENT_CONFIGURE_PROGRESS":
|
||||||
|
data1 = ffi_event.data1
|
||||||
|
if data1 == 0 or data1 == 1000:
|
||||||
|
success = data1 == 1000
|
||||||
|
yield "ac_configure_completed", dict(success=success)
|
||||||
|
elif name == "DC_EVENT_INCOMING_MSG":
|
||||||
|
msg = account.get_message_by_id(ffi_event.data2)
|
||||||
|
yield map_system_message(msg) or ("ac_incoming_message", dict(message=msg))
|
||||||
|
elif name == "DC_EVENT_MSGS_CHANGED":
|
||||||
|
if ffi_event.data2 != 0:
|
||||||
|
msg = account.get_message_by_id(ffi_event.data2)
|
||||||
|
if msg.is_outgoing():
|
||||||
|
res = map_system_message(msg)
|
||||||
|
if res and res[0].startswith("ac_member"):
|
||||||
|
yield res
|
||||||
|
yield "ac_outgoing_message", dict(message=msg)
|
||||||
|
elif msg.is_in_fresh():
|
||||||
|
yield map_system_message(msg) or ("ac_incoming_message", dict(message=msg))
|
||||||
|
elif name == "DC_EVENT_MSG_DELIVERED":
|
||||||
|
msg = account.get_message_by_id(ffi_event.data2)
|
||||||
|
yield "ac_message_delivered", dict(message=msg)
|
||||||
|
elif name == "DC_EVENT_CHAT_MODIFIED":
|
||||||
|
chat = account.get_chat_by_id(ffi_event.data1)
|
||||||
|
yield "ac_chat_modified", dict(chat=chat)
|
||||||
101
python/src/deltachat/hookspec.py
Normal file
@@ -0,0 +1,101 @@
|
|||||||
|
""" Hooks for Python bindings to Delta Chat Core Rust CFFI"""
|
||||||
|
|
||||||
|
import pluggy
|
||||||
|
|
||||||
|
|
||||||
|
account_spec_name = "deltachat-account"
|
||||||
|
account_hookspec = pluggy.HookspecMarker(account_spec_name)
|
||||||
|
account_hookimpl = pluggy.HookimplMarker(account_spec_name)
|
||||||
|
|
||||||
|
global_spec_name = "deltachat-global"
|
||||||
|
global_hookspec = pluggy.HookspecMarker(global_spec_name)
|
||||||
|
global_hookimpl = pluggy.HookimplMarker(global_spec_name)
|
||||||
|
|
||||||
|
|
||||||
|
class PerAccount:
|
||||||
|
""" per-Account-instance hook specifications.
|
||||||
|
|
||||||
|
All hooks are executed in a dedicated Event thread.
|
||||||
|
Hooks are not allowed to block/last long as this
|
||||||
|
blocks overall event processing on the python side.
|
||||||
|
"""
|
||||||
|
@classmethod
|
||||||
|
def _make_plugin_manager(cls):
|
||||||
|
pm = pluggy.PluginManager(account_spec_name)
|
||||||
|
pm.add_hookspecs(cls)
|
||||||
|
return pm
|
||||||
|
|
||||||
|
@account_hookspec
|
||||||
|
def ac_process_ffi_event(self, ffi_event):
|
||||||
|
""" process a CFFI low level events for a given account.
|
||||||
|
|
||||||
|
ffi_event has "name", "data1", "data2" values as specified
|
||||||
|
with `DC_EVENT_* <https://c.delta.chat/group__DC__EVENT.html>`_.
|
||||||
|
|
||||||
|
DANGER: this hook is executed from the callback invoked by core.
|
||||||
|
Hook implementations need to be short running and can typically
|
||||||
|
not call back into core because this would easily cause recursion issues.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@account_hookspec
|
||||||
|
def ac_log_line(self, message):
|
||||||
|
""" log a message related to the account. """
|
||||||
|
|
||||||
|
@account_hookspec
|
||||||
|
def ac_configure_completed(self, success):
|
||||||
|
""" Called after a configure process completed. """
|
||||||
|
|
||||||
|
@account_hookspec
|
||||||
|
def ac_incoming_message(self, message):
|
||||||
|
""" Called on any incoming message (to deaddrop or chat). """
|
||||||
|
|
||||||
|
@account_hookspec
|
||||||
|
def ac_outgoing_message(self, message):
|
||||||
|
""" Called on each outgoing message (both system and "normal")."""
|
||||||
|
|
||||||
|
@account_hookspec
|
||||||
|
def ac_message_delivered(self, message):
|
||||||
|
""" Called when an outgoing message has been delivered to SMTP. """
|
||||||
|
|
||||||
|
@account_hookspec
|
||||||
|
def ac_chat_modified(self, chat):
|
||||||
|
""" Chat was created or modified regarding membership, avatar, title. """
|
||||||
|
|
||||||
|
@account_hookspec
|
||||||
|
def ac_member_added(self, chat, contact, message):
|
||||||
|
""" Called for each contact added to an accepted chat. """
|
||||||
|
|
||||||
|
@account_hookspec
|
||||||
|
def ac_member_removed(self, chat, contact, message):
|
||||||
|
""" Called for each contact removed from a chat. """
|
||||||
|
|
||||||
|
|
||||||
|
class Global:
|
||||||
|
""" global hook specifications using a per-process singleton
|
||||||
|
plugin manager instance.
|
||||||
|
|
||||||
|
"""
|
||||||
|
_plugin_manager = None
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _get_plugin_manager(cls):
|
||||||
|
if cls._plugin_manager is None:
|
||||||
|
cls._plugin_manager = pm = pluggy.PluginManager(global_spec_name)
|
||||||
|
pm.add_hookspecs(cls)
|
||||||
|
return cls._plugin_manager
|
||||||
|
|
||||||
|
@global_hookspec
|
||||||
|
def dc_account_init(self, account):
|
||||||
|
""" called when `Account::__init__()` function starts executing. """
|
||||||
|
|
||||||
|
@global_hookspec
|
||||||
|
def dc_account_extra_configure(self, account):
|
||||||
|
""" Called when account configuration successfully finished.
|
||||||
|
|
||||||
|
This hook can be used to perform extra work before
|
||||||
|
ac_configure_completed is called.
|
||||||
|
"""
|
||||||
|
|
||||||
|
@global_hookspec
|
||||||
|
def dc_account_after_shutdown(self, account):
|
||||||
|
""" Called after the account has been shutdown. """
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
""" chatting related objects: Contact, Chat, Message. """
|
""" The Message object. """
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import shutil
|
|
||||||
from . import props
|
from . import props
|
||||||
from .cutil import from_dc_charpointer, as_dc_charpointer
|
from .cutil import from_dc_charpointer, as_dc_charpointer
|
||||||
from .capi import lib, ffi
|
from .capi import lib, ffi
|
||||||
@@ -13,12 +12,11 @@ class Message(object):
|
|||||||
""" Message object.
|
""" Message object.
|
||||||
|
|
||||||
You obtain instances of it through :class:`deltachat.account.Account` or
|
You obtain instances of it through :class:`deltachat.account.Account` or
|
||||||
:class:`deltachat.chatting.Chat`.
|
:class:`deltachat.chat.Chat`.
|
||||||
"""
|
"""
|
||||||
def __init__(self, account, dc_msg):
|
def __init__(self, account, dc_msg):
|
||||||
self.account = account
|
self.account = account
|
||||||
self._dc_context = account._dc_context
|
assert isinstance(self.account._dc_context, ffi.CData)
|
||||||
assert isinstance(self._dc_context, ffi.CData)
|
|
||||||
assert isinstance(dc_msg, ffi.CData)
|
assert isinstance(dc_msg, ffi.CData)
|
||||||
assert dc_msg != ffi.NULL
|
assert dc_msg != ffi.NULL
|
||||||
self._dc_msg = dc_msg
|
self._dc_msg = dc_msg
|
||||||
@@ -29,7 +27,11 @@ class Message(object):
|
|||||||
return self.account == other.account and self.id == other.id
|
return self.account == other.account and self.id == other.id
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<Message id={} dc_context={}>".format(self.id, self._dc_context)
|
c = self.get_sender_contact()
|
||||||
|
typ = "outgoing" if self.is_outgoing() else "incoming"
|
||||||
|
return "<Message {} sys={} {} id={} sender={}/{} chat={}/{}>".format(
|
||||||
|
typ, self.is_system_message(), repr(self.text[:10]),
|
||||||
|
self.id, c.id, c.addr, self.chat.id, self.chat.get_name())
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_db(cls, account, id):
|
def from_db(cls, account, id):
|
||||||
@@ -51,6 +53,20 @@ class Message(object):
|
|||||||
lib.dc_msg_unref
|
lib.dc_msg_unref
|
||||||
))
|
))
|
||||||
|
|
||||||
|
def create_chat(self):
|
||||||
|
""" create or get an existing chat (group) object for this message.
|
||||||
|
|
||||||
|
If the message is a deaddrop contact request
|
||||||
|
the sender will become an accepted contact.
|
||||||
|
|
||||||
|
:returns: a :class:`deltachat.chat.Chat` object.
|
||||||
|
"""
|
||||||
|
from .chat import Chat
|
||||||
|
chat_id = lib.dc_create_chat_by_msg_id(self.account._dc_context, self.id)
|
||||||
|
ctx = self.account._dc_context
|
||||||
|
self._dc_msg = ffi.gc(lib.dc_get_msg(ctx, self.id), lib.dc_msg_unref)
|
||||||
|
return Chat(self.account, chat_id)
|
||||||
|
|
||||||
@props.with_doc
|
@props.with_doc
|
||||||
def text(self):
|
def text(self):
|
||||||
"""unicode text of this messages (might be empty if not a text message). """
|
"""unicode text of this messages (might be empty if not a text message). """
|
||||||
@@ -58,8 +74,6 @@ class Message(object):
|
|||||||
|
|
||||||
def set_text(self, text):
|
def set_text(self, text):
|
||||||
"""set text of this message. """
|
"""set text of this message. """
|
||||||
assert self.id > 0, "message not prepared"
|
|
||||||
assert self.is_out_preparing()
|
|
||||||
lib.dc_msg_set_text(self._dc_msg, as_dc_charpointer(text))
|
lib.dc_msg_set_text(self._dc_msg, as_dc_charpointer(text))
|
||||||
|
|
||||||
@props.with_doc
|
@props.with_doc
|
||||||
@@ -72,19 +86,6 @@ class Message(object):
|
|||||||
mtype = ffi.NULL if mime_type is None else as_dc_charpointer(mime_type)
|
mtype = ffi.NULL if mime_type is None else as_dc_charpointer(mime_type)
|
||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
raise ValueError("path does not exist: {!r}".format(path))
|
raise ValueError("path does not exist: {!r}".format(path))
|
||||||
blobdir = self.account.get_blobdir()
|
|
||||||
if not path.startswith(blobdir):
|
|
||||||
for i in range(50):
|
|
||||||
ext = "" if i == 0 else "-" + str(i)
|
|
||||||
dest = os.path.join(blobdir, os.path.basename(path) + ext)
|
|
||||||
if os.path.exists(dest):
|
|
||||||
continue
|
|
||||||
shutil.copyfile(path, dest)
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise ValueError("could not create blobdir-path for {}".format(path))
|
|
||||||
path = dest
|
|
||||||
assert path.startswith(blobdir), path
|
|
||||||
lib.dc_msg_set_file(self._dc_msg, as_dc_charpointer(path), mtype)
|
lib.dc_msg_set_file(self._dc_msg, as_dc_charpointer(path), mtype)
|
||||||
|
|
||||||
@props.with_doc
|
@props.with_doc
|
||||||
@@ -97,20 +98,42 @@ class Message(object):
|
|||||||
"""mime type of the file (if it exists)"""
|
"""mime type of the file (if it exists)"""
|
||||||
return from_dc_charpointer(lib.dc_msg_get_filemime(self._dc_msg))
|
return from_dc_charpointer(lib.dc_msg_get_filemime(self._dc_msg))
|
||||||
|
|
||||||
|
def is_system_message(self):
|
||||||
|
""" return True if this message is a system/info message. """
|
||||||
|
return bool(lib.dc_msg_is_info(self._dc_msg))
|
||||||
|
|
||||||
def is_setup_message(self):
|
def is_setup_message(self):
|
||||||
""" return True if this message is a setup message. """
|
""" return True if this message is a setup message. """
|
||||||
return lib.dc_msg_is_setupmessage(self._dc_msg)
|
return lib.dc_msg_is_setupmessage(self._dc_msg)
|
||||||
|
|
||||||
|
def get_setupcodebegin(self):
|
||||||
|
""" return the first characters of a setup code in a setup message. """
|
||||||
|
return from_dc_charpointer(lib.dc_msg_get_setupcodebegin(self._dc_msg))
|
||||||
|
|
||||||
|
def is_encrypted(self):
|
||||||
|
""" return True if this message was encrypted. """
|
||||||
|
return bool(lib.dc_msg_get_showpadlock(self._dc_msg))
|
||||||
|
|
||||||
|
def is_forwarded(self):
|
||||||
|
""" return True if this message was forwarded. """
|
||||||
|
return bool(lib.dc_msg_is_forwarded(self._dc_msg))
|
||||||
|
|
||||||
def get_message_info(self):
|
def get_message_info(self):
|
||||||
""" Return informational text for a single message.
|
""" Return informational text for a single message.
|
||||||
|
|
||||||
The text is multiline and may contain eg. the raw text of the message.
|
The text is multiline and may contain eg. the raw text of the message.
|
||||||
"""
|
"""
|
||||||
return from_dc_charpointer(lib.dc_get_msg_info(self._dc_context, self.id))
|
return from_dc_charpointer(lib.dc_get_msg_info(self.account._dc_context, self.id))
|
||||||
|
|
||||||
def continue_key_transfer(self, setup_code):
|
def continue_key_transfer(self, setup_code):
|
||||||
""" extract key and use it as primary key for this account. """
|
""" extract key and use it as primary key for this account. """
|
||||||
lib.dc_continue_key_transfer(self._dc_context, self.id, as_dc_charpointer(setup_code))
|
res = lib.dc_continue_key_transfer(
|
||||||
|
self.account._dc_context,
|
||||||
|
self.id,
|
||||||
|
as_dc_charpointer(setup_code)
|
||||||
|
)
|
||||||
|
if res == 0:
|
||||||
|
raise ValueError("could not decrypt")
|
||||||
|
|
||||||
@props.with_doc
|
@props.with_doc
|
||||||
def time_sent(self):
|
def time_sent(self):
|
||||||
@@ -140,31 +163,38 @@ class Message(object):
|
|||||||
:returns: email-mime message object (with headers only, no body).
|
:returns: email-mime message object (with headers only, no body).
|
||||||
"""
|
"""
|
||||||
import email.parser
|
import email.parser
|
||||||
mime_headers = lib.dc_get_mime_headers(self._dc_context, self.id)
|
mime_headers = lib.dc_get_mime_headers(self.account._dc_context, self.id)
|
||||||
if mime_headers:
|
if mime_headers:
|
||||||
s = ffi.string(ffi.gc(mime_headers, lib.dc_str_unref))
|
s = ffi.string(ffi.gc(mime_headers, lib.dc_str_unref))
|
||||||
if isinstance(s, bytes):
|
if isinstance(s, bytes):
|
||||||
s = s.decode("ascii")
|
return email.message_from_bytes(s)
|
||||||
return email.message_from_string(s)
|
return email.message_from_string(s)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def chat(self):
|
def chat(self):
|
||||||
"""chat this message was posted in.
|
"""chat this message was posted in.
|
||||||
|
|
||||||
:returns: :class:`deltachat.chatting.Chat` object
|
:returns: :class:`deltachat.chat.Chat` object
|
||||||
"""
|
"""
|
||||||
from .chatting import Chat
|
from .chat import Chat
|
||||||
chat_id = lib.dc_msg_get_chat_id(self._dc_msg)
|
chat_id = lib.dc_msg_get_chat_id(self._dc_msg)
|
||||||
return Chat(self.account, chat_id)
|
return Chat(self.account, chat_id)
|
||||||
|
|
||||||
|
def get_sender_chat(self):
|
||||||
|
"""return the 1:1 chat with the sender of this message.
|
||||||
|
|
||||||
|
:returns: :class:`deltachat.chat.Chat` instance
|
||||||
|
"""
|
||||||
|
return self.get_sender_contact().get_chat()
|
||||||
|
|
||||||
def get_sender_contact(self):
|
def get_sender_contact(self):
|
||||||
"""return the contact of who wrote the message.
|
"""return the contact of who wrote the message.
|
||||||
|
|
||||||
:returns: :class:`deltachat.chatting.Contact` instance
|
:returns: :class:`deltachat.chat.Contact` instance
|
||||||
"""
|
"""
|
||||||
from .chatting import Contact
|
from .contact import Contact
|
||||||
contact_id = lib.dc_msg_get_from_id(self._dc_msg)
|
contact_id = lib.dc_msg_get_from_id(self._dc_msg)
|
||||||
return Contact(self._dc_context, contact_id)
|
return Contact(self.account, contact_id)
|
||||||
|
|
||||||
#
|
#
|
||||||
# Message State query methods
|
# Message State query methods
|
||||||
@@ -172,11 +202,11 @@ class Message(object):
|
|||||||
@property
|
@property
|
||||||
def _msgstate(self):
|
def _msgstate(self):
|
||||||
if self.id == 0:
|
if self.id == 0:
|
||||||
dc_msg = self.message._dc_msg
|
dc_msg = self._dc_msg
|
||||||
else:
|
else:
|
||||||
# load message from db to get a fresh/current state
|
# load message from db to get a fresh/current state
|
||||||
dc_msg = ffi.gc(
|
dc_msg = ffi.gc(
|
||||||
lib.dc_get_msg(self._dc_context, self.id),
|
lib.dc_get_msg(self.account._dc_context, self.id),
|
||||||
lib.dc_msg_unref
|
lib.dc_msg_unref
|
||||||
)
|
)
|
||||||
return lib.dc_msg_get_state(dc_msg)
|
return lib.dc_msg_get_state(dc_msg)
|
||||||
@@ -205,6 +235,13 @@ class Message(object):
|
|||||||
"""
|
"""
|
||||||
return self._msgstate == const.DC_STATE_IN_SEEN
|
return self._msgstate == const.DC_STATE_IN_SEEN
|
||||||
|
|
||||||
|
def is_outgoing(self):
|
||||||
|
"""Return True if Message is outgoing. """
|
||||||
|
return self._msgstate in (
|
||||||
|
const.DC_STATE_OUT_PREPARING, const.DC_STATE_OUT_PENDING,
|
||||||
|
const.DC_STATE_OUT_FAILED, const.DC_STATE_OUT_MDN_RCVD,
|
||||||
|
const.DC_STATE_OUT_DELIVERED)
|
||||||
|
|
||||||
def is_out_preparing(self):
|
def is_out_preparing(self):
|
||||||
"""Return True if Message is outgoing, but its file is being prepared.
|
"""Return True if Message is outgoing, but its file is being prepared.
|
||||||
"""
|
"""
|
||||||
@@ -267,6 +304,10 @@ class Message(object):
|
|||||||
""" return True if it's a file message. """
|
""" return True if it's a file message. """
|
||||||
return self._view_type == const.DC_MSG_FILE
|
return self._view_type == const.DC_MSG_FILE
|
||||||
|
|
||||||
|
def mark_seen(self):
|
||||||
|
""" mark this message as seen. """
|
||||||
|
self.account.mark_seen_messages([self.id])
|
||||||
|
|
||||||
|
|
||||||
# some code for handling DC_MSG_* view types
|
# some code for handling DC_MSG_* view types
|
||||||
|
|
||||||
@@ -286,3 +327,29 @@ def get_viewtype_code_from_name(view_type_name):
|
|||||||
return code
|
return code
|
||||||
raise ValueError("message typecode not found for {!r}, "
|
raise ValueError("message typecode not found for {!r}, "
|
||||||
"available {!r}".format(view_type_name, list(_view_type_mapping.values())))
|
"available {!r}".format(view_type_name, list(_view_type_mapping.values())))
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# some helper code for turning system messages into hook events
|
||||||
|
#
|
||||||
|
|
||||||
|
def map_system_message(msg):
|
||||||
|
if msg.is_system_message():
|
||||||
|
res = parse_system_add_remove(msg.text)
|
||||||
|
if res:
|
||||||
|
contact = msg.account.get_contact_by_addr(res[1])
|
||||||
|
if contact:
|
||||||
|
d = dict(chat=msg.chat, contact=contact, message=msg)
|
||||||
|
return "ac_member_" + res[0], d
|
||||||
|
|
||||||
|
|
||||||
|
def parse_system_add_remove(text):
|
||||||
|
# Member Me (x@y) removed by a@b.
|
||||||
|
# Member x@y removed by a@b
|
||||||
|
text = text.lower()
|
||||||
|
parts = text.split()
|
||||||
|
if parts[0] == "member":
|
||||||
|
if parts[2] in ("removed", "added"):
|
||||||
|
return parts[2], parts[1]
|
||||||
|
if parts[3] in ("removed", "added"):
|
||||||
|
return parts[3], parts[2].strip("()")
|
||||||
|
|||||||
47
python/src/deltachat/provider.py
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
"""Provider info class."""
|
||||||
|
|
||||||
|
from .capi import ffi, lib
|
||||||
|
from .cutil import as_dc_charpointer, from_dc_charpointer
|
||||||
|
|
||||||
|
|
||||||
|
class ProviderNotFoundError(Exception):
|
||||||
|
"""The provider information was not found."""
|
||||||
|
|
||||||
|
|
||||||
|
class Provider(object):
|
||||||
|
"""Provider information.
|
||||||
|
|
||||||
|
:param domain: The email to get the provider info for.
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, account, addr):
|
||||||
|
provider = ffi.gc(
|
||||||
|
lib.dc_provider_new_from_email(account._dc_context, as_dc_charpointer(addr)),
|
||||||
|
lib.dc_provider_unref,
|
||||||
|
)
|
||||||
|
if provider == ffi.NULL:
|
||||||
|
raise ProviderNotFoundError("Provider not found")
|
||||||
|
self._provider = provider
|
||||||
|
|
||||||
|
@property
|
||||||
|
def overview_page(self):
|
||||||
|
"""URL to the overview page of the provider on providers.delta.chat."""
|
||||||
|
return from_dc_charpointer(
|
||||||
|
lib.dc_provider_get_overview_page(self._provider))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def get_before_login_hints(self):
|
||||||
|
"""Should be shown to the user on login."""
|
||||||
|
return from_dc_charpointer(
|
||||||
|
lib.dc_provider_get_before_login_hints(self._provider))
|
||||||
|
|
||||||
|
@property
|
||||||
|
def status(self):
|
||||||
|
"""The status of the provider information.
|
||||||
|
|
||||||
|
This is one of the
|
||||||
|
:attr:`deltachat.const.DC_PROVIDER_STATUS_OK`,
|
||||||
|
:attr:`deltachat.const.DC_PROVIDER_STATUS_PREPARATION` or
|
||||||
|
:attr:`deltachat.const.DC_PROVIDER_STATUS_BROKEN` constants.
|
||||||
|
"""
|
||||||
|
return lib.dc_provider_get_status(self._provider)
|
||||||
507
python/src/deltachat/testplugin.py
Normal file
@@ -0,0 +1,507 @@
|
|||||||
|
from __future__ import print_function
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import io
|
||||||
|
import subprocess
|
||||||
|
import queue
|
||||||
|
import threading
|
||||||
|
import fnmatch
|
||||||
|
import time
|
||||||
|
import weakref
|
||||||
|
import tempfile
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
import requests
|
||||||
|
|
||||||
|
from . import Account, const
|
||||||
|
from .capi import lib
|
||||||
|
from .events import FFIEventLogger, FFIEventTracker
|
||||||
|
from _pytest._code import Source
|
||||||
|
from deltachat import direct_imap
|
||||||
|
|
||||||
|
import deltachat
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_addoption(parser):
|
||||||
|
parser.addoption(
|
||||||
|
"--liveconfig", action="store", default=None,
|
||||||
|
help="a file with >=2 lines where each line "
|
||||||
|
"contains NAME=VALUE config settings for one account"
|
||||||
|
)
|
||||||
|
parser.addoption(
|
||||||
|
"--ignored", action="store_true",
|
||||||
|
help="Also run tests marked with the ignored marker",
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_configure(config):
|
||||||
|
cfg = config.getoption('--liveconfig')
|
||||||
|
if not cfg:
|
||||||
|
cfg = os.getenv('DCC_NEW_TMP_EMAIL')
|
||||||
|
if cfg:
|
||||||
|
config.option.liveconfig = cfg
|
||||||
|
|
||||||
|
# Make sure we don't get garbled output because threads keep running
|
||||||
|
# collect all ever created accounts in a weakref-set (so we don't
|
||||||
|
# keep objects unneccessarily alive) and enable/disable logging
|
||||||
|
# for each pytest test phase # (setup/call/teardown).
|
||||||
|
# Additionally make the acfactory use a logging/no-logging default.
|
||||||
|
|
||||||
|
class LoggingAspect:
|
||||||
|
def __init__(self):
|
||||||
|
self._accounts = weakref.WeakSet()
|
||||||
|
|
||||||
|
@deltachat.global_hookimpl
|
||||||
|
def dc_account_init(self, account):
|
||||||
|
self._accounts.add(account)
|
||||||
|
|
||||||
|
def disable_logging(self, item):
|
||||||
|
for acc in self._accounts:
|
||||||
|
acc.disable_logging()
|
||||||
|
acfactory = item.funcargs.get("acfactory")
|
||||||
|
if acfactory:
|
||||||
|
acfactory.set_logging_default(False)
|
||||||
|
|
||||||
|
def enable_logging(self, item):
|
||||||
|
for acc in self._accounts:
|
||||||
|
acc.enable_logging()
|
||||||
|
acfactory = item.funcargs.get("acfactory")
|
||||||
|
if acfactory:
|
||||||
|
acfactory.set_logging_default(True)
|
||||||
|
|
||||||
|
@pytest.hookimpl(hookwrapper=True)
|
||||||
|
def pytest_runtest_setup(self, item):
|
||||||
|
if item.get_closest_marker("ignored"):
|
||||||
|
if not item.config.getvalue("ignored"):
|
||||||
|
pytest.skip("use --ignored to run this test")
|
||||||
|
self.enable_logging(item)
|
||||||
|
yield
|
||||||
|
self.disable_logging(item)
|
||||||
|
|
||||||
|
@pytest.hookimpl(hookwrapper=True)
|
||||||
|
def pytest_pyfunc_call(self, pyfuncitem):
|
||||||
|
self.enable_logging(pyfuncitem)
|
||||||
|
yield
|
||||||
|
self.disable_logging(pyfuncitem)
|
||||||
|
|
||||||
|
@pytest.hookimpl(hookwrapper=True)
|
||||||
|
def pytest_runtest_teardown(self, item):
|
||||||
|
self.enable_logging(item)
|
||||||
|
yield
|
||||||
|
self.disable_logging(item)
|
||||||
|
|
||||||
|
la = LoggingAspect()
|
||||||
|
config.pluginmanager.register(la)
|
||||||
|
deltachat.register_global_plugin(la)
|
||||||
|
|
||||||
|
|
||||||
|
def pytest_report_header(config, startdir):
|
||||||
|
summary = []
|
||||||
|
|
||||||
|
t = tempfile.mktemp()
|
||||||
|
try:
|
||||||
|
ac = Account(t)
|
||||||
|
info = ac.get_info()
|
||||||
|
ac.shutdown()
|
||||||
|
finally:
|
||||||
|
os.remove(t)
|
||||||
|
summary.extend(['Deltachat core={} sqlite={} journal_mode={}'.format(
|
||||||
|
info['deltachat_core_version'],
|
||||||
|
info['sqlite_version'],
|
||||||
|
info['journal_mode'],
|
||||||
|
)])
|
||||||
|
|
||||||
|
cfg = config.option.liveconfig
|
||||||
|
if cfg:
|
||||||
|
if "?" in cfg:
|
||||||
|
url, token = cfg.split("?", 1)
|
||||||
|
summary.append('Liveconfig provider: {}?<token ommitted>'.format(url))
|
||||||
|
else:
|
||||||
|
summary.append('Liveconfig file: {}'.format(cfg))
|
||||||
|
return summary
|
||||||
|
|
||||||
|
|
||||||
|
class SessionLiveConfigFromFile:
|
||||||
|
def __init__(self, fn):
|
||||||
|
self.fn = fn
|
||||||
|
self.configlist = []
|
||||||
|
for line in open(fn):
|
||||||
|
if line.strip() and not line.strip().startswith('#'):
|
||||||
|
d = {}
|
||||||
|
for part in line.split():
|
||||||
|
name, value = part.split("=")
|
||||||
|
d[name] = value
|
||||||
|
self.configlist.append(d)
|
||||||
|
|
||||||
|
def get(self, index):
|
||||||
|
return self.configlist[index]
|
||||||
|
|
||||||
|
def exists(self):
|
||||||
|
return bool(self.configlist)
|
||||||
|
|
||||||
|
|
||||||
|
class SessionLiveConfigFromURL:
|
||||||
|
def __init__(self, url):
|
||||||
|
self.configlist = []
|
||||||
|
self.url = url
|
||||||
|
|
||||||
|
def get(self, index):
|
||||||
|
try:
|
||||||
|
return self.configlist[index]
|
||||||
|
except IndexError:
|
||||||
|
assert index == len(self.configlist), index
|
||||||
|
res = requests.post(self.url)
|
||||||
|
if res.status_code != 200:
|
||||||
|
pytest.skip("creating newtmpuser failed {!r}".format(res))
|
||||||
|
d = res.json()
|
||||||
|
config = dict(addr=d["email"], mail_pw=d["password"])
|
||||||
|
self.configlist.append(config)
|
||||||
|
return config
|
||||||
|
|
||||||
|
def exists(self):
|
||||||
|
return bool(self.configlist)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(scope="session")
|
||||||
|
def session_liveconfig(request):
|
||||||
|
liveconfig_opt = request.config.option.liveconfig
|
||||||
|
if liveconfig_opt:
|
||||||
|
if liveconfig_opt.startswith("http"):
|
||||||
|
return SessionLiveConfigFromURL(liveconfig_opt)
|
||||||
|
else:
|
||||||
|
return SessionLiveConfigFromFile(liveconfig_opt)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def data(request):
|
||||||
|
class Data:
|
||||||
|
def __init__(self):
|
||||||
|
# trying to find test data heuristically
|
||||||
|
# because we are run from a dev-setup with pytest direct,
|
||||||
|
# through tox, and then maybe also from deltachat-binding
|
||||||
|
# users like "deltabot".
|
||||||
|
self.paths = [os.path.normpath(x) for x in [
|
||||||
|
os.path.join(os.path.dirname(request.fspath.strpath), "data"),
|
||||||
|
os.path.join(os.path.dirname(__file__), "..", "..", "..", "test-data")
|
||||||
|
]]
|
||||||
|
|
||||||
|
def get_path(self, bn):
|
||||||
|
""" return path of file or None if it doesn't exist. """
|
||||||
|
for path in self.paths:
|
||||||
|
fn = os.path.join(path, *bn.split("/"))
|
||||||
|
if os.path.exists(fn):
|
||||||
|
return fn
|
||||||
|
print("WARNING: path does not exist: {!r}".format(fn))
|
||||||
|
|
||||||
|
def read_path(self, bn, mode="r"):
|
||||||
|
fn = self.get_path(bn)
|
||||||
|
if fn is not None:
|
||||||
|
with open(fn, mode) as f:
|
||||||
|
return f.read()
|
||||||
|
|
||||||
|
return Data()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def acfactory(pytestconfig, tmpdir, request, session_liveconfig, data):
|
||||||
|
|
||||||
|
class AccountMaker:
|
||||||
|
def __init__(self):
|
||||||
|
self.live_count = 0
|
||||||
|
self.offline_count = 0
|
||||||
|
self._finalizers = []
|
||||||
|
self._accounts = []
|
||||||
|
self.init_time = time.time()
|
||||||
|
self._generated_keys = ["alice", "bob", "charlie",
|
||||||
|
"dom", "elena", "fiona"]
|
||||||
|
self.set_logging_default(False)
|
||||||
|
deltachat.register_global_plugin(direct_imap)
|
||||||
|
|
||||||
|
def finalize(self):
|
||||||
|
while self._finalizers:
|
||||||
|
fin = self._finalizers.pop()
|
||||||
|
fin()
|
||||||
|
|
||||||
|
while self._accounts:
|
||||||
|
acc = self._accounts.pop()
|
||||||
|
acc.shutdown()
|
||||||
|
acc.disable_logging()
|
||||||
|
deltachat.unregister_global_plugin(direct_imap)
|
||||||
|
|
||||||
|
def make_account(self, path, logid, quiet=False):
|
||||||
|
ac = Account(path, logging=self._logging)
|
||||||
|
ac._evtracker = ac.add_account_plugin(FFIEventTracker(ac))
|
||||||
|
ac.addr = ac.get_self_contact().addr
|
||||||
|
ac.set_config("displayname", logid)
|
||||||
|
if not quiet:
|
||||||
|
ac.add_account_plugin(FFIEventLogger(ac))
|
||||||
|
self._accounts.append(ac)
|
||||||
|
return ac
|
||||||
|
|
||||||
|
def set_logging_default(self, logging):
|
||||||
|
self._logging = bool(logging)
|
||||||
|
|
||||||
|
def get_unconfigured_account(self):
|
||||||
|
self.offline_count += 1
|
||||||
|
tmpdb = tmpdir.join("offlinedb%d" % self.offline_count)
|
||||||
|
ac = self.make_account(tmpdb.strpath, logid="ac{}".format(self.offline_count))
|
||||||
|
ac._evtracker.init_time = self.init_time
|
||||||
|
ac._evtracker.set_timeout(2)
|
||||||
|
return ac
|
||||||
|
|
||||||
|
def _preconfigure_key(self, account, addr):
|
||||||
|
# Only set a key if we haven't used it yet for another account.
|
||||||
|
if self._generated_keys:
|
||||||
|
keyname = self._generated_keys.pop(0)
|
||||||
|
fname_pub = data.read_path("key/{name}-public.asc".format(name=keyname))
|
||||||
|
fname_sec = data.read_path("key/{name}-secret.asc".format(name=keyname))
|
||||||
|
if fname_pub and fname_sec:
|
||||||
|
account._preconfigure_keypair(addr, fname_pub, fname_sec)
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print("WARN: could not use preconfigured keys for {!r}".format(addr))
|
||||||
|
|
||||||
|
def get_configured_offline_account(self):
|
||||||
|
ac = self.get_unconfigured_account()
|
||||||
|
|
||||||
|
# do a pseudo-configured account
|
||||||
|
addr = "addr{}@offline.org".format(self.offline_count)
|
||||||
|
ac.set_config("addr", addr)
|
||||||
|
self._preconfigure_key(ac, addr)
|
||||||
|
lib.dc_set_config(ac._dc_context, b"configured_addr", addr.encode("ascii"))
|
||||||
|
ac.set_config("mail_pw", "123")
|
||||||
|
lib.dc_set_config(ac._dc_context, b"configured_mail_pw", b"123")
|
||||||
|
lib.dc_set_config(ac._dc_context, b"configured", b"1")
|
||||||
|
return ac
|
||||||
|
|
||||||
|
def get_online_config(self, pre_generated_key=True, quiet=False):
|
||||||
|
if not session_liveconfig:
|
||||||
|
pytest.skip("specify DCC_NEW_TMP_EMAIL or --liveconfig")
|
||||||
|
configdict = session_liveconfig.get(self.live_count)
|
||||||
|
self.live_count += 1
|
||||||
|
if "e2ee_enabled" not in configdict:
|
||||||
|
configdict["e2ee_enabled"] = "1"
|
||||||
|
|
||||||
|
# Enable strict certificate checks for online accounts
|
||||||
|
configdict["imap_certificate_checks"] = str(const.DC_CERTCK_STRICT)
|
||||||
|
configdict["smtp_certificate_checks"] = str(const.DC_CERTCK_STRICT)
|
||||||
|
|
||||||
|
tmpdb = tmpdir.join("livedb%d" % self.live_count)
|
||||||
|
ac = self.make_account(tmpdb.strpath, logid="ac{}".format(self.live_count), quiet=quiet)
|
||||||
|
if pre_generated_key:
|
||||||
|
self._preconfigure_key(ac, configdict['addr'])
|
||||||
|
ac._evtracker.init_time = self.init_time
|
||||||
|
ac._evtracker.set_timeout(30)
|
||||||
|
return ac, dict(configdict)
|
||||||
|
|
||||||
|
def get_online_configuring_account(self, mvbox=False, sentbox=False, move=False,
|
||||||
|
pre_generated_key=True, quiet=False, config={}):
|
||||||
|
ac, configdict = self.get_online_config(
|
||||||
|
pre_generated_key=pre_generated_key, quiet=quiet)
|
||||||
|
configdict.update(config)
|
||||||
|
configdict["mvbox_watch"] = str(int(mvbox))
|
||||||
|
configdict["mvbox_move"] = str(int(move))
|
||||||
|
configdict["sentbox_watch"] = str(int(sentbox))
|
||||||
|
ac.update_config(configdict)
|
||||||
|
ac._configtracker = ac.configure()
|
||||||
|
return ac
|
||||||
|
|
||||||
|
def get_one_online_account(self, pre_generated_key=True, mvbox=False, move=False):
|
||||||
|
ac1 = self.get_online_configuring_account(
|
||||||
|
pre_generated_key=pre_generated_key, mvbox=mvbox, move=move)
|
||||||
|
self.wait_configure_and_start_io()
|
||||||
|
return ac1
|
||||||
|
|
||||||
|
def get_two_online_accounts(self, move=False, quiet=False):
|
||||||
|
ac1 = self.get_online_configuring_account(move=move, quiet=quiet)
|
||||||
|
ac2 = self.get_online_configuring_account(quiet=quiet)
|
||||||
|
self.wait_configure_and_start_io()
|
||||||
|
return ac1, ac2
|
||||||
|
|
||||||
|
def get_many_online_accounts(self, num, move=True):
|
||||||
|
accounts = [self.get_online_configuring_account(move=move, quiet=True)
|
||||||
|
for i in range(num)]
|
||||||
|
self.wait_configure_and_start_io()
|
||||||
|
for acc in accounts:
|
||||||
|
acc.add_account_plugin(FFIEventLogger(acc))
|
||||||
|
return accounts
|
||||||
|
|
||||||
|
def clone_online_account(self, account, pre_generated_key=True):
|
||||||
|
self.live_count += 1
|
||||||
|
tmpdb = tmpdir.join("livedb%d" % self.live_count)
|
||||||
|
ac = self.make_account(tmpdb.strpath, logid="ac{}".format(self.live_count))
|
||||||
|
if pre_generated_key:
|
||||||
|
self._preconfigure_key(ac, account.get_config("addr"))
|
||||||
|
ac._evtracker.init_time = self.init_time
|
||||||
|
ac._evtracker.set_timeout(30)
|
||||||
|
ac.update_config(dict(
|
||||||
|
addr=account.get_config("addr"),
|
||||||
|
mail_pw=account.get_config("mail_pw"),
|
||||||
|
mvbox_watch=account.get_config("mvbox_watch"),
|
||||||
|
mvbox_move=account.get_config("mvbox_move"),
|
||||||
|
sentbox_watch=account.get_config("sentbox_watch"),
|
||||||
|
))
|
||||||
|
ac._configtracker = ac.configure()
|
||||||
|
return ac
|
||||||
|
|
||||||
|
def wait_configure_and_start_io(self):
|
||||||
|
for acc in self._accounts:
|
||||||
|
if hasattr(acc, "_configtracker"):
|
||||||
|
acc._configtracker.wait_finish()
|
||||||
|
del acc._configtracker
|
||||||
|
acc.set_config("bcc_self", "0")
|
||||||
|
if acc.is_configured() and not acc.is_started():
|
||||||
|
acc.start_io()
|
||||||
|
print("{}: {} account was successfully setup".format(
|
||||||
|
acc.get_config("displayname"), acc.get_config("addr")))
|
||||||
|
|
||||||
|
def run_bot_process(self, module, ffi=True):
|
||||||
|
fn = module.__file__
|
||||||
|
|
||||||
|
bot_ac, bot_cfg = self.get_online_config()
|
||||||
|
|
||||||
|
# Avoid starting ac so we don't interfere with the bot operating on
|
||||||
|
# the same database.
|
||||||
|
self._accounts.remove(bot_ac)
|
||||||
|
|
||||||
|
args = [
|
||||||
|
sys.executable,
|
||||||
|
"-u",
|
||||||
|
fn,
|
||||||
|
"--email", bot_cfg["addr"],
|
||||||
|
"--password", bot_cfg["mail_pw"],
|
||||||
|
bot_ac.db_path,
|
||||||
|
]
|
||||||
|
if ffi:
|
||||||
|
args.insert(-1, "--show-ffi")
|
||||||
|
print("$", " ".join(args))
|
||||||
|
popen = subprocess.Popen(
|
||||||
|
args=args,
|
||||||
|
stdin=subprocess.DEVNULL,
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.STDOUT, # combine stdout/stderr in one stream
|
||||||
|
bufsize=0, # line buffering
|
||||||
|
close_fds=True, # close all FDs other than 0/1/2
|
||||||
|
universal_newlines=True # give back text
|
||||||
|
)
|
||||||
|
bot = BotProcess(popen, bot_cfg)
|
||||||
|
self._finalizers.append(bot.kill)
|
||||||
|
return bot
|
||||||
|
|
||||||
|
def dump_imap_summary(self, logfile):
|
||||||
|
for ac in self._accounts:
|
||||||
|
imap = getattr(ac, "direct_imap", None)
|
||||||
|
if imap is not None:
|
||||||
|
try:
|
||||||
|
imap.idle_done()
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
imap.dump_account_info(logfile=logfile)
|
||||||
|
imap.dump_imap_structures(tmpdir, logfile=logfile)
|
||||||
|
|
||||||
|
def get_accepted_chat(self, ac1, ac2):
|
||||||
|
ac2.create_chat(ac1)
|
||||||
|
return ac1.create_chat(ac2)
|
||||||
|
|
||||||
|
def introduce_each_other(self, accounts, sending=True):
|
||||||
|
to_wait = []
|
||||||
|
for i, acc in enumerate(accounts):
|
||||||
|
for acc2 in accounts[i + 1:]:
|
||||||
|
chat = self.get_accepted_chat(acc, acc2)
|
||||||
|
if sending:
|
||||||
|
chat.send_text("hi")
|
||||||
|
to_wait.append(acc2)
|
||||||
|
acc2.create_chat(acc).send_text("hi back")
|
||||||
|
to_wait.append(acc)
|
||||||
|
for acc in to_wait:
|
||||||
|
acc._evtracker.wait_next_incoming_message()
|
||||||
|
|
||||||
|
am = AccountMaker()
|
||||||
|
request.addfinalizer(am.finalize)
|
||||||
|
yield am
|
||||||
|
if hasattr(request.node, "rep_call") and request.node.rep_call.failed:
|
||||||
|
logfile = io.StringIO()
|
||||||
|
am.dump_imap_summary(logfile=logfile)
|
||||||
|
print(logfile.getvalue())
|
||||||
|
# request.node.add_report_section("call", "imap-server-state", s)
|
||||||
|
|
||||||
|
|
||||||
|
class BotProcess:
|
||||||
|
def __init__(self, popen, bot_cfg):
|
||||||
|
self.popen = popen
|
||||||
|
self.addr = bot_cfg["addr"]
|
||||||
|
|
||||||
|
# we read stdout as quickly as we can in a thread and make
|
||||||
|
# the (unicode) lines available for readers through a queue.
|
||||||
|
self.stdout_queue = queue.Queue()
|
||||||
|
self.stdout_thread = t = threading.Thread(target=self._run_stdout_thread, name="bot-stdout-thread")
|
||||||
|
t.setDaemon(1)
|
||||||
|
t.start()
|
||||||
|
|
||||||
|
def _run_stdout_thread(self):
|
||||||
|
try:
|
||||||
|
while 1:
|
||||||
|
line = self.popen.stdout.readline()
|
||||||
|
if not line:
|
||||||
|
break
|
||||||
|
line = line.strip()
|
||||||
|
self.stdout_queue.put(line)
|
||||||
|
print("bot-stdout: ", line)
|
||||||
|
finally:
|
||||||
|
self.stdout_queue.put(None)
|
||||||
|
|
||||||
|
def kill(self):
|
||||||
|
self.popen.kill()
|
||||||
|
|
||||||
|
def wait(self, timeout=30):
|
||||||
|
self.popen.wait(timeout=timeout)
|
||||||
|
|
||||||
|
def fnmatch_lines(self, pattern_lines):
|
||||||
|
patterns = [x.strip() for x in Source(pattern_lines.rstrip()).lines if x.strip()]
|
||||||
|
for next_pattern in patterns:
|
||||||
|
print("+++FNMATCH:", next_pattern)
|
||||||
|
ignored = []
|
||||||
|
while 1:
|
||||||
|
line = self.stdout_queue.get(timeout=15)
|
||||||
|
if line is None:
|
||||||
|
if ignored:
|
||||||
|
print("BOT stdout terminated after these lines")
|
||||||
|
for line in ignored:
|
||||||
|
print(line)
|
||||||
|
raise IOError("BOT stdout-thread terminated")
|
||||||
|
if fnmatch.fnmatch(line, next_pattern):
|
||||||
|
print("+++MATCHED:", line)
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
print("+++IGN:", line)
|
||||||
|
ignored.append(line)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def tmp_db_path(tmpdir):
|
||||||
|
return tmpdir.join("test.db").strpath
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture
|
||||||
|
def lp():
|
||||||
|
class Printer:
|
||||||
|
def sec(self, msg):
|
||||||
|
print()
|
||||||
|
print("=" * 10, msg, "=" * 10)
|
||||||
|
|
||||||
|
def step(self, msg):
|
||||||
|
print("-" * 5, "step " + msg, "-" * 5)
|
||||||
|
|
||||||
|
return Printer()
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.hookimpl(tryfirst=True, hookwrapper=True)
|
||||||
|
def pytest_runtest_makereport(item, call):
|
||||||
|
# execute all other hooks to obtain the report object
|
||||||
|
outcome = yield
|
||||||
|
rep = outcome.get_result()
|
||||||
|
|
||||||
|
# set a report attribute for each phase of a call, which can
|
||||||
|
# be "setup", "call", "teardown"
|
||||||
|
|
||||||
|
setattr(item, "rep_" + rep.when, rep)
|
||||||
90
python/src/deltachat/tracker.py
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
|
||||||
|
from queue import Queue
|
||||||
|
from threading import Event
|
||||||
|
|
||||||
|
from .hookspec import account_hookimpl, Global
|
||||||
|
|
||||||
|
|
||||||
|
class ImexFailed(RuntimeError):
|
||||||
|
""" Exception for signalling that import/export operations failed."""
|
||||||
|
|
||||||
|
|
||||||
|
class ImexTracker:
|
||||||
|
def __init__(self):
|
||||||
|
self._imex_events = Queue()
|
||||||
|
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_process_ffi_event(self, ffi_event):
|
||||||
|
if ffi_event.name == "DC_EVENT_IMEX_PROGRESS":
|
||||||
|
self._imex_events.put(ffi_event.data1)
|
||||||
|
elif ffi_event.name == "DC_EVENT_IMEX_FILE_WRITTEN":
|
||||||
|
self._imex_events.put(ffi_event.data2)
|
||||||
|
|
||||||
|
def wait_finish(self, progress_timeout=60):
|
||||||
|
""" Return list of written files, raise ValueError if ExportFailed. """
|
||||||
|
files_written = []
|
||||||
|
while True:
|
||||||
|
ev = self._imex_events.get(timeout=progress_timeout)
|
||||||
|
if isinstance(ev, str):
|
||||||
|
files_written.append(ev)
|
||||||
|
elif ev == 0:
|
||||||
|
raise ImexFailed("export failed, exp-files: {}".format(files_written))
|
||||||
|
elif ev == 1000:
|
||||||
|
return files_written
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigureFailed(RuntimeError):
|
||||||
|
""" Exception for signalling that configuration failed."""
|
||||||
|
|
||||||
|
|
||||||
|
class ConfigureTracker:
|
||||||
|
ConfigureFailed = ConfigureFailed
|
||||||
|
|
||||||
|
def __init__(self, account):
|
||||||
|
self.account = account
|
||||||
|
self._configure_events = Queue()
|
||||||
|
self._smtp_finished = Event()
|
||||||
|
self._imap_finished = Event()
|
||||||
|
self._ffi_events = []
|
||||||
|
self._progress = Queue()
|
||||||
|
self._gm = Global._get_plugin_manager()
|
||||||
|
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_process_ffi_event(self, ffi_event):
|
||||||
|
self._ffi_events.append(ffi_event)
|
||||||
|
if ffi_event.name == "DC_EVENT_SMTP_CONNECTED":
|
||||||
|
self._smtp_finished.set()
|
||||||
|
elif ffi_event.name == "DC_EVENT_IMAP_CONNECTED":
|
||||||
|
self._imap_finished.set()
|
||||||
|
elif ffi_event.name == "DC_EVENT_CONFIGURE_PROGRESS":
|
||||||
|
self._progress.put(ffi_event.data1)
|
||||||
|
|
||||||
|
@account_hookimpl
|
||||||
|
def ac_configure_completed(self, success):
|
||||||
|
if success:
|
||||||
|
self._gm.hook.dc_account_extra_configure(account=self.account)
|
||||||
|
self._configure_events.put(success)
|
||||||
|
self.account.remove_account_plugin(self)
|
||||||
|
|
||||||
|
def wait_smtp_connected(self):
|
||||||
|
""" wait until smtp is configured. """
|
||||||
|
self._smtp_finished.wait()
|
||||||
|
|
||||||
|
def wait_imap_connected(self):
|
||||||
|
""" wait until smtp is configured. """
|
||||||
|
self._imap_finished.wait()
|
||||||
|
|
||||||
|
def wait_progress(self, data1=None):
|
||||||
|
while 1:
|
||||||
|
evdata = self._progress.get()
|
||||||
|
if data1 is None or evdata == data1:
|
||||||
|
break
|
||||||
|
|
||||||
|
def wait_finish(self):
|
||||||
|
""" wait until configure is completed.
|
||||||
|
|
||||||
|
Raise Exception if Configure failed
|
||||||
|
"""
|
||||||
|
if not self._configure_events.get():
|
||||||
|
content = "\n".join(map(str, self._ffi_events))
|
||||||
|
raise ConfigureFailed(content)
|
||||||
@@ -10,4 +10,6 @@ if __name__ == "__main__":
|
|||||||
for relpath in os.listdir(workspacedir):
|
for relpath in os.listdir(workspacedir):
|
||||||
if relpath.startswith("deltachat"):
|
if relpath.startswith("deltachat"):
|
||||||
p = os.path.join(workspacedir, relpath)
|
p = os.path.join(workspacedir, relpath)
|
||||||
subprocess.check_call(["auditwheel", "repair", p, "-w", workspacedir])
|
subprocess.check_call(
|
||||||
|
["auditwheel", "repair", p, "-w", workspacedir,
|
||||||
|
"--plat", "manylinux2014_x86_64"])
|
||||||
|
|||||||
@@ -1,235 +0,0 @@
|
|||||||
from __future__ import print_function
|
|
||||||
import os
|
|
||||||
import pytest
|
|
||||||
import requests
|
|
||||||
import time
|
|
||||||
from deltachat import Account
|
|
||||||
from deltachat.capi import lib
|
|
||||||
import tempfile
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_addoption(parser):
|
|
||||||
parser.addoption(
|
|
||||||
"--liveconfig", action="store", default=None,
|
|
||||||
help="a file with >=2 lines where each line "
|
|
||||||
"contains NAME=VALUE config settings for one account"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_configure(config):
|
|
||||||
cfg = config.getoption('--liveconfig')
|
|
||||||
if not cfg:
|
|
||||||
cfg = os.getenv('DCC_PY_LIVECONFIG')
|
|
||||||
if cfg:
|
|
||||||
config.option.liveconfig = cfg
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.hookimpl(trylast=True)
|
|
||||||
def pytest_runtest_call(item):
|
|
||||||
# perform early finalization because we otherwise get cloberred
|
|
||||||
# output from concurrent threads printing between execution
|
|
||||||
# of the test function and the teardown phase of that test function
|
|
||||||
if "acfactory" in item.funcargs:
|
|
||||||
print("*"*30, "finalizing", "*"*30)
|
|
||||||
acfactory = item.funcargs["acfactory"]
|
|
||||||
acfactory.finalize()
|
|
||||||
|
|
||||||
|
|
||||||
def pytest_report_header(config, startdir):
|
|
||||||
summary = []
|
|
||||||
|
|
||||||
t = tempfile.mktemp()
|
|
||||||
try:
|
|
||||||
ac = Account(t, eventlogging=False)
|
|
||||||
info = ac.get_info()
|
|
||||||
ac.shutdown()
|
|
||||||
finally:
|
|
||||||
os.remove(t)
|
|
||||||
summary.extend(['Deltachat core={} sqlite={}'.format(
|
|
||||||
info['deltachat_core_version'],
|
|
||||||
info['sqlite_version'],
|
|
||||||
)])
|
|
||||||
|
|
||||||
cfg = config.option.liveconfig
|
|
||||||
if cfg:
|
|
||||||
if "#" in cfg:
|
|
||||||
url, token = cfg.split("#", 1)
|
|
||||||
summary.append('Liveconfig provider: {}#<token ommitted>'.format(url))
|
|
||||||
else:
|
|
||||||
summary.append('Liveconfig file: {}'.format(cfg))
|
|
||||||
return summary
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
|
||||||
def data():
|
|
||||||
class Data:
|
|
||||||
def __init__(self):
|
|
||||||
self.path = os.path.join(os.path.dirname(__file__), "data")
|
|
||||||
|
|
||||||
def get_path(self, bn):
|
|
||||||
fn = os.path.join(self.path, bn)
|
|
||||||
assert os.path.exists(fn)
|
|
||||||
return fn
|
|
||||||
return Data()
|
|
||||||
|
|
||||||
|
|
||||||
class SessionLiveConfigFromFile:
|
|
||||||
def __init__(self, fn):
|
|
||||||
self.fn = fn
|
|
||||||
self.configlist = []
|
|
||||||
for line in open(fn):
|
|
||||||
if line.strip() and not line.strip().startswith('#'):
|
|
||||||
d = {}
|
|
||||||
for part in line.split():
|
|
||||||
name, value = part.split("=")
|
|
||||||
d[name] = value
|
|
||||||
self.configlist.append(d)
|
|
||||||
|
|
||||||
def get(self, index):
|
|
||||||
return self.configlist[index]
|
|
||||||
|
|
||||||
def exists(self):
|
|
||||||
return bool(self.configlist)
|
|
||||||
|
|
||||||
|
|
||||||
class SessionLiveConfigFromURL:
|
|
||||||
def __init__(self, url, create_token):
|
|
||||||
self.configlist = []
|
|
||||||
for i in range(2):
|
|
||||||
res = requests.post(url, json={"token_create_user": int(create_token)})
|
|
||||||
if res.status_code != 200:
|
|
||||||
pytest.skip("creating newtmpuser failed {!r}".format(res))
|
|
||||||
d = res.json()
|
|
||||||
config = dict(addr=d["email"], mail_pw=d["password"])
|
|
||||||
self.configlist.append(config)
|
|
||||||
|
|
||||||
def get(self, index):
|
|
||||||
return self.configlist[index]
|
|
||||||
|
|
||||||
def exists(self):
|
|
||||||
return bool(self.configlist)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(scope="session")
|
|
||||||
def session_liveconfig(request):
|
|
||||||
liveconfig_opt = request.config.option.liveconfig
|
|
||||||
if liveconfig_opt:
|
|
||||||
if liveconfig_opt.startswith("http"):
|
|
||||||
url, create_token = liveconfig_opt.split("#", 1)
|
|
||||||
return SessionLiveConfigFromURL(url, create_token)
|
|
||||||
else:
|
|
||||||
return SessionLiveConfigFromFile(liveconfig_opt)
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def acfactory(pytestconfig, tmpdir, request, session_liveconfig):
|
|
||||||
|
|
||||||
class AccountMaker:
|
|
||||||
def __init__(self):
|
|
||||||
self.live_count = 0
|
|
||||||
self.offline_count = 0
|
|
||||||
self._finalizers = []
|
|
||||||
self.init_time = time.time()
|
|
||||||
|
|
||||||
def finalize(self):
|
|
||||||
while self._finalizers:
|
|
||||||
fin = self._finalizers.pop()
|
|
||||||
fin()
|
|
||||||
|
|
||||||
def get_unconfigured_account(self):
|
|
||||||
self.offline_count += 1
|
|
||||||
tmpdb = tmpdir.join("offlinedb%d" % self.offline_count)
|
|
||||||
ac = Account(tmpdb.strpath, logid="ac{}".format(self.offline_count))
|
|
||||||
ac._evlogger.init_time = self.init_time
|
|
||||||
ac._evlogger.set_timeout(2)
|
|
||||||
self._finalizers.append(ac.shutdown)
|
|
||||||
return ac
|
|
||||||
|
|
||||||
def get_configured_offline_account(self):
|
|
||||||
ac = self.get_unconfigured_account()
|
|
||||||
|
|
||||||
# do a pseudo-configured account
|
|
||||||
addr = "addr{}@offline.org".format(self.offline_count)
|
|
||||||
ac.set_config("addr", addr)
|
|
||||||
lib.dc_set_config(ac._dc_context, b"configured_addr", addr.encode("ascii"))
|
|
||||||
ac.set_config("mail_pw", "123")
|
|
||||||
lib.dc_set_config(ac._dc_context, b"configured_mail_pw", b"123")
|
|
||||||
lib.dc_set_config(ac._dc_context, b"configured", b"1")
|
|
||||||
return ac
|
|
||||||
|
|
||||||
def get_online_configuring_account(self):
|
|
||||||
if not session_liveconfig:
|
|
||||||
pytest.skip("specify DCC_PY_LIVECONFIG or --liveconfig")
|
|
||||||
configdict = session_liveconfig.get(self.live_count)
|
|
||||||
self.live_count += 1
|
|
||||||
if "e2ee_enabled" not in configdict:
|
|
||||||
configdict["e2ee_enabled"] = "1"
|
|
||||||
tmpdb = tmpdir.join("livedb%d" % self.live_count)
|
|
||||||
ac = Account(tmpdb.strpath, logid="ac{}".format(self.live_count))
|
|
||||||
ac._evlogger.init_time = self.init_time
|
|
||||||
ac._evlogger.set_timeout(30)
|
|
||||||
ac.configure(**configdict)
|
|
||||||
ac.start_threads()
|
|
||||||
self._finalizers.append(ac.shutdown)
|
|
||||||
return ac
|
|
||||||
|
|
||||||
def clone_online_account(self, account):
|
|
||||||
self.live_count += 1
|
|
||||||
tmpdb = tmpdir.join("livedb%d" % self.live_count)
|
|
||||||
ac = Account(tmpdb.strpath, logid="ac{}".format(self.live_count))
|
|
||||||
ac._evlogger.init_time = self.init_time
|
|
||||||
ac._evlogger.set_timeout(30)
|
|
||||||
ac.configure(addr=account.get_config("addr"), mail_pw=account.get_config("mail_pw"))
|
|
||||||
ac.start_threads()
|
|
||||||
self._finalizers.append(ac.shutdown)
|
|
||||||
return ac
|
|
||||||
|
|
||||||
return AccountMaker()
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def tmp_db_path(tmpdir):
|
|
||||||
return tmpdir.join("test.db").strpath
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
|
||||||
def lp():
|
|
||||||
class Printer:
|
|
||||||
def sec(self, msg):
|
|
||||||
print()
|
|
||||||
print("=" * 10, msg, "=" * 10)
|
|
||||||
|
|
||||||
def step(self, msg):
|
|
||||||
print("-" * 5, "step " + msg, "-" * 5)
|
|
||||||
return Printer()
|
|
||||||
|
|
||||||
|
|
||||||
def wait_configuration_progress(account, target):
|
|
||||||
while 1:
|
|
||||||
evt_name, data1, data2 = \
|
|
||||||
account._evlogger.get_matching("DC_EVENT_CONFIGURE_PROGRESS")
|
|
||||||
if data1 >= target:
|
|
||||||
print("** CONFIG PROGRESS {}".format(target), account)
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
def wait_successful_IMAP_SMTP_connection(account):
|
|
||||||
imap_ok = smtp_ok = False
|
|
||||||
while not imap_ok or not smtp_ok:
|
|
||||||
evt_name, data1, data2 = \
|
|
||||||
account._evlogger.get_matching("DC_EVENT_(IMAP|SMTP)_CONNECTED")
|
|
||||||
if evt_name == "DC_EVENT_IMAP_CONNECTED":
|
|
||||||
imap_ok = True
|
|
||||||
print("** IMAP OK", account)
|
|
||||||
if evt_name == "DC_EVENT_SMTP_CONNECTED":
|
|
||||||
smtp_ok = True
|
|
||||||
print("** SMTP OK", account)
|
|
||||||
print("** IMAP and SMTP logins successful", account)
|
|
||||||
|
|
||||||
|
|
||||||
def wait_msgs_changed(account, chat_id, msg_id=None):
|
|
||||||
ev = account._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
|
||||||
assert ev[1] == chat_id
|
|
||||||
if msg_id is not None:
|
|
||||||
assert ev[2] == msg_id
|
|
||||||
return ev[2]
|
|
||||||
|
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 2.7 KiB |
1
python/tests/data/key
Symbolic link
@@ -0,0 +1 @@
|
|||||||
|
../../../test-data/key
|
||||||
135
python/tests/stress_test_db.py
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
|
||||||
|
import time
|
||||||
|
import threading
|
||||||
|
import pytest
|
||||||
|
import os
|
||||||
|
from queue import Queue, Empty
|
||||||
|
|
||||||
|
import deltachat
|
||||||
|
|
||||||
|
|
||||||
|
def test_db_busy_error(acfactory, tmpdir):
|
||||||
|
starttime = time.time()
|
||||||
|
log_lock = threading.RLock()
|
||||||
|
|
||||||
|
def log(string):
|
||||||
|
with log_lock:
|
||||||
|
print("%3.2f %s" % (time.time() - starttime, string))
|
||||||
|
|
||||||
|
# make a number of accounts
|
||||||
|
accounts = acfactory.get_many_online_accounts(3, quiet=True)
|
||||||
|
log("created %s accounts" % len(accounts))
|
||||||
|
|
||||||
|
# put a bigfile into each account
|
||||||
|
for acc in accounts:
|
||||||
|
acc.bigfile = os.path.join(acc.get_blobdir(), "bigfile")
|
||||||
|
with open(acc.bigfile, "wb") as f:
|
||||||
|
f.write(b"01234567890"*1000_000)
|
||||||
|
log("created %s bigfiles" % len(accounts))
|
||||||
|
|
||||||
|
contact_addrs = [acc.get_self_contact().addr for acc in accounts]
|
||||||
|
chat = accounts[0].create_group_chat("stress-group")
|
||||||
|
for addr in contact_addrs[1:]:
|
||||||
|
chat.add_contact(chat.account.create_contact(addr))
|
||||||
|
|
||||||
|
# setup auto-responder bots which report back failures/actions
|
||||||
|
report_queue = Queue()
|
||||||
|
|
||||||
|
def report_func(replier, report_type, *report_args):
|
||||||
|
report_queue.put((replier, report_type, report_args))
|
||||||
|
|
||||||
|
# each replier receives all events and sends report events to receive_queue
|
||||||
|
repliers = []
|
||||||
|
for acc in accounts:
|
||||||
|
replier = AutoReplier(acc, log=log, num_send=500, num_bigfiles=5, report_func=report_func)
|
||||||
|
acc.add_account_plugin(replier)
|
||||||
|
repliers.append(replier)
|
||||||
|
|
||||||
|
# kick off message sending
|
||||||
|
# after which repliers will reply to each other
|
||||||
|
chat.send_text("hello")
|
||||||
|
|
||||||
|
alive_count = len(accounts)
|
||||||
|
while alive_count > 0:
|
||||||
|
try:
|
||||||
|
replier, report_type, report_args = report_queue.get(timeout=10)
|
||||||
|
except Empty:
|
||||||
|
log("timeout waiting for next event")
|
||||||
|
pytest.fail("timeout exceeded")
|
||||||
|
if report_type == ReportType.exit:
|
||||||
|
replier.log("EXIT")
|
||||||
|
elif report_type == ReportType.ffi_error:
|
||||||
|
replier.log("ERROR: {}".format(report_args[0]))
|
||||||
|
elif report_type == ReportType.message_echo:
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
raise ValueError("{} unknown report type {}, args={}".format(
|
||||||
|
addr, report_type, report_args
|
||||||
|
))
|
||||||
|
alive_count -= 1
|
||||||
|
replier.log("shutting down")
|
||||||
|
replier.account.shutdown()
|
||||||
|
replier.log("shut down complete, remaining={}".format(alive_count))
|
||||||
|
|
||||||
|
|
||||||
|
class ReportType:
|
||||||
|
exit = "exit"
|
||||||
|
ffi_error = "ffi-error"
|
||||||
|
message_echo = "message-echo"
|
||||||
|
|
||||||
|
|
||||||
|
class AutoReplier:
|
||||||
|
def __init__(self, account, log, num_send, num_bigfiles, report_func):
|
||||||
|
self.account = account
|
||||||
|
self._log = log
|
||||||
|
self.report_func = report_func
|
||||||
|
self.num_send = num_send
|
||||||
|
self.num_bigfiles = num_bigfiles
|
||||||
|
self.current_sent = 0
|
||||||
|
self.addr = self.account.get_self_contact().addr
|
||||||
|
|
||||||
|
self._thread = threading.Thread(
|
||||||
|
name="Stats{}".format(self.account),
|
||||||
|
target=self.thread_stats
|
||||||
|
)
|
||||||
|
self._thread.setDaemon(True)
|
||||||
|
self._thread.start()
|
||||||
|
|
||||||
|
def log(self, message):
|
||||||
|
self._log("{} {}".format(self.addr, message))
|
||||||
|
|
||||||
|
def thread_stats(self):
|
||||||
|
# XXX later use, for now we just quit
|
||||||
|
return
|
||||||
|
while 1:
|
||||||
|
time.sleep(1.0)
|
||||||
|
break
|
||||||
|
|
||||||
|
@deltachat.account_hookimpl
|
||||||
|
def ac_incoming_message(self, message):
|
||||||
|
if self.current_sent >= self.num_send:
|
||||||
|
self.report_func(self, ReportType.exit)
|
||||||
|
return
|
||||||
|
message.create_chat()
|
||||||
|
message.mark_seen()
|
||||||
|
self.log("incoming message: {}".format(message))
|
||||||
|
|
||||||
|
self.current_sent += 1
|
||||||
|
# we are still alive, let's send a reply
|
||||||
|
if self.num_bigfiles and self.current_sent % (self.num_send / self.num_bigfiles) == 0:
|
||||||
|
message.chat.send_text("send big file as reply to: {}".format(message.text))
|
||||||
|
msg = message.chat.send_file(self.account.bigfile)
|
||||||
|
else:
|
||||||
|
msg = message.chat.send_text("got message id {}, small text reply".format(message.id))
|
||||||
|
assert msg.text
|
||||||
|
self.log("message-sent: {}".format(msg))
|
||||||
|
self.report_func(self, ReportType.message_echo)
|
||||||
|
if self.current_sent >= self.num_send:
|
||||||
|
self.report_func(self, ReportType.exit)
|
||||||
|
return
|
||||||
|
|
||||||
|
@deltachat.account_hookimpl
|
||||||
|
def ac_process_ffi_event(self, ffi_event):
|
||||||
|
self.log(ffi_event)
|
||||||
|
if ffi_event.name == "DC_EVENT_ERROR":
|
||||||
|
self.report_func(self, ReportType.ffi_error, ffi_event)
|
||||||
@@ -1,69 +1,115 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
|
import os.path
|
||||||
|
import shutil
|
||||||
|
|
||||||
|
import pytest
|
||||||
from filecmp import cmp
|
from filecmp import cmp
|
||||||
|
|
||||||
from deltachat import const
|
from deltachat import const
|
||||||
from conftest import wait_configuration_progress, wait_msgs_changed
|
|
||||||
|
|
||||||
|
|
||||||
class TestInCreation:
|
def wait_msg_delivered(account, msg_list):
|
||||||
|
""" wait for one or more MSG_DELIVERED events to match msg_list contents. """
|
||||||
|
msg_list = list(msg_list)
|
||||||
|
while msg_list:
|
||||||
|
ev = account._evtracker.get_matching("DC_EVENT_MSG_DELIVERED")
|
||||||
|
msg_list.remove((ev.data1, ev.data2))
|
||||||
|
|
||||||
|
|
||||||
|
def wait_msgs_changed(account, msgs_list):
|
||||||
|
""" wait for one or more MSGS_CHANGED events to match msgs_list contents. """
|
||||||
|
account.log("waiting for msgs_list={}".format(msgs_list))
|
||||||
|
msgs_list = list(msgs_list)
|
||||||
|
while msgs_list:
|
||||||
|
ev = account._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
|
for i, (data1, data2) in enumerate(msgs_list):
|
||||||
|
if ev.data1 == data1:
|
||||||
|
if data2 is None or ev.data2 == data2:
|
||||||
|
del msgs_list[i]
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
account.log("waiting mismatch data1={} data2={}".format(data1, data2))
|
||||||
|
return ev.data1, ev.data2
|
||||||
|
|
||||||
|
|
||||||
|
class TestOnlineInCreation:
|
||||||
|
def test_increation_not_blobdir(self, tmpdir, acfactory, lp):
|
||||||
|
ac1, ac2 = acfactory.get_two_online_accounts()
|
||||||
|
chat = ac1.create_chat(ac2)
|
||||||
|
|
||||||
|
lp.sec("Creating in-creation file outside of blobdir")
|
||||||
|
assert tmpdir.strpath != ac1.get_blobdir()
|
||||||
|
src = tmpdir.join('file.txt').ensure(file=1)
|
||||||
|
with pytest.raises(Exception):
|
||||||
|
chat.prepare_message_file(src.strpath)
|
||||||
|
|
||||||
|
def test_no_increation_copies_to_blobdir(self, tmpdir, acfactory, lp):
|
||||||
|
ac1, ac2 = acfactory.get_two_online_accounts()
|
||||||
|
chat = ac1.create_chat(ac2)
|
||||||
|
|
||||||
|
lp.sec("Creating file outside of blobdir")
|
||||||
|
assert tmpdir.strpath != ac1.get_blobdir()
|
||||||
|
src = tmpdir.join('file.txt')
|
||||||
|
src.write("hello there\n")
|
||||||
|
chat.send_file(src.strpath)
|
||||||
|
|
||||||
|
blob_src = os.path.join(ac1.get_blobdir(), 'file.txt')
|
||||||
|
assert os.path.exists(blob_src), "file.txt not copied to blobdir"
|
||||||
|
|
||||||
def test_forward_increation(self, acfactory, data, lp):
|
def test_forward_increation(self, acfactory, data, lp):
|
||||||
ac1 = acfactory.get_online_configuring_account()
|
ac1, ac2 = acfactory.get_two_online_accounts()
|
||||||
ac2 = acfactory.get_online_configuring_account()
|
|
||||||
wait_configuration_progress(ac1, 1000)
|
|
||||||
wait_configuration_progress(ac2, 1000)
|
|
||||||
|
|
||||||
c2 = ac1.create_contact(email=ac2.get_config("addr"))
|
chat = ac1.create_chat(ac2)
|
||||||
chat = ac1.create_chat_by_contact(c2)
|
wait_msgs_changed(ac1, [(0, 0)]) # why no chat id?
|
||||||
assert chat.id >= const.DC_CHAT_ID_LAST_SPECIAL
|
|
||||||
wait_msgs_changed(ac1, 0, 0) # why no chat id?
|
|
||||||
|
|
||||||
lp.sec("create a message with a file in creation")
|
lp.sec("create a message with a file in creation")
|
||||||
path = data.get_path("d.png")
|
orig = data.get_path("d.png")
|
||||||
|
path = os.path.join(ac1.get_blobdir(), 'd.png')
|
||||||
|
with open(path, "x") as fp:
|
||||||
|
fp.write("preparing")
|
||||||
prepared_original = chat.prepare_message_file(path)
|
prepared_original = chat.prepare_message_file(path)
|
||||||
assert prepared_original.is_out_preparing()
|
assert prepared_original.is_out_preparing()
|
||||||
wait_msgs_changed(ac1, chat.id, prepared_original.id)
|
wait_msgs_changed(ac1, [(chat.id, prepared_original.id)])
|
||||||
|
|
||||||
lp.sec("forward the message while still in creation")
|
lp.sec("forward the message while still in creation")
|
||||||
chat2 = ac1.create_group_chat("newgroup")
|
chat2 = ac1.create_group_chat("newgroup")
|
||||||
chat2.add_contact(c2)
|
chat2.add_contact(ac2)
|
||||||
wait_msgs_changed(ac1, 0, 0) # why not chat id?
|
wait_msgs_changed(ac1, [(0, 0)]) # why not chat id?
|
||||||
ac1.forward_messages([prepared_original], chat2)
|
ac1.forward_messages([prepared_original], chat2)
|
||||||
# XXX there might be two EVENT_MSGS_CHANGED and only one of them
|
# XXX there might be two EVENT_MSGS_CHANGED and only one of them
|
||||||
# is the one caused by forwarding
|
# is the one caused by forwarding
|
||||||
forwarded_id = wait_msgs_changed(ac1, chat2.id)
|
_, forwarded_id = wait_msgs_changed(ac1, [(chat2.id, None)])
|
||||||
if forwarded_id == 0:
|
|
||||||
forwarded_id = wait_msgs_changed(ac1, chat2.id)
|
|
||||||
assert forwarded_id
|
|
||||||
forwarded_msg = ac1.get_message_by_id(forwarded_id)
|
forwarded_msg = ac1.get_message_by_id(forwarded_id)
|
||||||
assert forwarded_msg.is_out_preparing()
|
assert forwarded_msg.is_out_preparing()
|
||||||
|
|
||||||
lp.sec("finish creating the file and send it")
|
lp.sec("finish creating the file and send it")
|
||||||
assert prepared_original.is_out_preparing()
|
assert prepared_original.is_out_preparing()
|
||||||
|
shutil.copyfile(orig, path)
|
||||||
chat.send_prepared(prepared_original)
|
chat.send_prepared(prepared_original)
|
||||||
assert prepared_original.is_out_pending() or prepared_original.is_out_delivered()
|
assert prepared_original.is_out_pending() or prepared_original.is_out_delivered()
|
||||||
wait_msgs_changed(ac1, chat.id, prepared_original.id)
|
|
||||||
|
|
||||||
lp.sec("expect the forwarded message to be sent now too")
|
lp.sec("check that both forwarded and original message are proper.")
|
||||||
wait_msgs_changed(ac1, chat2.id, forwarded_id)
|
wait_msgs_changed(ac1, [(chat2.id, forwarded_id), (chat.id, prepared_original.id)])
|
||||||
|
|
||||||
fwd_msg = ac1.get_message_by_id(forwarded_id)
|
fwd_msg = ac1.get_message_by_id(forwarded_id)
|
||||||
assert fwd_msg.is_out_pending() or fwd_msg.is_out_delivered()
|
assert fwd_msg.is_out_pending() or fwd_msg.is_out_delivered()
|
||||||
|
|
||||||
lp.sec("wait for the messages to be delivered to SMTP")
|
lp.sec("wait for both messages to be delivered to SMTP")
|
||||||
ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
|
wait_msg_delivered(ac1, [
|
||||||
assert ev[1] == chat.id
|
(chat2.id, forwarded_id),
|
||||||
assert ev[2] == prepared_original.id
|
(chat.id, prepared_original.id)
|
||||||
ev = ac1._evlogger.get_matching("DC_EVENT_MSG_DELIVERED")
|
])
|
||||||
assert ev[1] == chat2.id
|
|
||||||
assert ev[2] == forwarded_id
|
|
||||||
|
|
||||||
lp.sec("wait1 for original or forwarded messages to arrive")
|
lp.sec("wait1 for original or forwarded messages to arrive")
|
||||||
ev1 = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
ev1 = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
assert ev1[1] >= const.DC_CHAT_ID_LAST_SPECIAL
|
assert ev1.data1 > const.DC_CHAT_ID_LAST_SPECIAL
|
||||||
received_original = ac2.get_message_by_id(ev1[2])
|
received_original = ac2.get_message_by_id(ev1.data2)
|
||||||
assert cmp(received_original.filename, path, False)
|
assert cmp(received_original.filename, orig, shallow=False)
|
||||||
|
|
||||||
lp.sec("wait2 for original or forwarded messages to arrive")
|
lp.sec("wait2 for original or forwarded messages to arrive")
|
||||||
ev2 = ac2._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
ev2 = ac2._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
assert ev2[1] >= const.DC_CHAT_ID_LAST_SPECIAL
|
assert ev2.data1 > const.DC_CHAT_ID_LAST_SPECIAL
|
||||||
assert ev2[1] != ev1[1]
|
assert ev2.data1 != ev1.data1
|
||||||
received_copy = ac2.get_message_by_id(ev2[2])
|
received_copy = ac2.get_message_by_id(ev2.data2)
|
||||||
assert cmp(received_copy.filename, path, False)
|
assert cmp(received_copy.filename, orig, shallow=False)
|
||||||
|
|||||||
@@ -1,54 +1,52 @@
|
|||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
from deltachat import capi, const, set_context_callback, clear_context_callback
|
|
||||||
|
from queue import Queue
|
||||||
|
from deltachat import capi, cutil, const
|
||||||
|
from deltachat import register_global_plugin
|
||||||
|
from deltachat.hookspec import global_hookimpl
|
||||||
from deltachat.capi import ffi
|
from deltachat.capi import ffi
|
||||||
from deltachat.capi import lib
|
from deltachat.capi import lib
|
||||||
from deltachat.account import EventLogger
|
# from deltachat.account import EventLogger
|
||||||
|
|
||||||
|
|
||||||
def test_empty_context():
|
def test_empty_context():
|
||||||
ctx = capi.lib.dc_context_new(capi.ffi.NULL, capi.ffi.NULL, capi.ffi.NULL)
|
ctx = capi.lib.dc_context_new(capi.ffi.NULL, capi.ffi.NULL, capi.ffi.NULL)
|
||||||
capi.lib.dc_close(ctx)
|
capi.lib.dc_context_unref(ctx)
|
||||||
|
|
||||||
|
|
||||||
def test_callback_None2int():
|
def test_dc_close_events(tmpdir, acfactory):
|
||||||
ctx = capi.lib.dc_context_new(capi.lib.py_dc_callback, ffi.NULL, ffi.NULL)
|
ac1 = acfactory.get_unconfigured_account()
|
||||||
set_context_callback(ctx, lambda *args: None)
|
|
||||||
capi.lib.dc_close(ctx)
|
|
||||||
clear_context_callback(ctx)
|
|
||||||
|
|
||||||
|
# register after_shutdown function
|
||||||
|
shutdowns = Queue()
|
||||||
|
|
||||||
def test_dc_close_events():
|
class ShutdownPlugin:
|
||||||
ctx = capi.lib.dc_context_new(capi.lib.py_dc_callback, ffi.NULL, ffi.NULL)
|
@global_hookimpl
|
||||||
evlog = EventLogger(ctx)
|
def dc_account_after_shutdown(self, account):
|
||||||
evlog.set_timeout(5)
|
assert account._dc_context is None
|
||||||
set_context_callback(ctx, lambda ctx, evt_name, data1, data2: evlog(evt_name, data1, data2))
|
shutdowns.put(account)
|
||||||
capi.lib.dc_close(ctx)
|
register_global_plugin(ShutdownPlugin())
|
||||||
|
assert hasattr(ac1, "_dc_context")
|
||||||
def find(info_string):
|
ac1.shutdown()
|
||||||
while 1:
|
shutdowns.get(timeout=2)
|
||||||
ev = evlog.get_matching("DC_EVENT_INFO", check_error=False)
|
|
||||||
data2 = ev[2]
|
|
||||||
if info_string in data2:
|
|
||||||
return
|
|
||||||
else:
|
|
||||||
print("skipping event", *ev)
|
|
||||||
|
|
||||||
find("disconnecting INBOX-watch")
|
|
||||||
find("disconnecting sentbox-thread")
|
|
||||||
find("disconnecting mvbox-thread")
|
|
||||||
find("disconnecting SMTP")
|
|
||||||
find("Database closed")
|
|
||||||
|
|
||||||
|
|
||||||
def test_wrong_db(tmpdir):
|
def test_wrong_db(tmpdir):
|
||||||
dc_context = ffi.gc(
|
|
||||||
lib.dc_context_new(lib.py_dc_callback, ffi.NULL, ffi.NULL),
|
|
||||||
lib.dc_context_unref,
|
|
||||||
)
|
|
||||||
p = tmpdir.join("hello.db")
|
p = tmpdir.join("hello.db")
|
||||||
# write an invalid database file
|
# write an invalid database file
|
||||||
p.write("x123" * 10)
|
p.write("x123" * 10)
|
||||||
assert not lib.dc_open(dc_context, p.strpath.encode("ascii"), ffi.NULL)
|
|
||||||
|
assert ffi.NULL == lib.dc_context_new(ffi.NULL, p.strpath.encode("ascii"), ffi.NULL)
|
||||||
|
|
||||||
|
|
||||||
|
def test_empty_blobdir(tmpdir):
|
||||||
|
db_fname = tmpdir.join("hello.db")
|
||||||
|
# Apparently some client code expects this to be the same as passing NULL.
|
||||||
|
ctx = ffi.gc(
|
||||||
|
lib.dc_context_new(ffi.NULL, db_fname.strpath.encode("ascii"), b""),
|
||||||
|
lib.dc_context_unref,
|
||||||
|
)
|
||||||
|
assert ctx != ffi.NULL
|
||||||
|
|
||||||
|
|
||||||
def test_event_defines():
|
def test_event_defines():
|
||||||
@@ -57,21 +55,50 @@ def test_event_defines():
|
|||||||
|
|
||||||
|
|
||||||
def test_sig():
|
def test_sig():
|
||||||
sig = capi.lib.dc_get_event_signature_types
|
sig = capi.lib.dc_event_has_string_data
|
||||||
assert sig(const.DC_EVENT_INFO) == 2
|
assert not sig(const.DC_EVENT_MSGS_CHANGED)
|
||||||
assert sig(const.DC_EVENT_WARNING) == 2
|
assert sig(const.DC_EVENT_INFO)
|
||||||
assert sig(const.DC_EVENT_ERROR) == 2
|
assert sig(const.DC_EVENT_WARNING)
|
||||||
assert sig(const.DC_EVENT_SMTP_CONNECTED) == 2
|
assert sig(const.DC_EVENT_ERROR)
|
||||||
assert sig(const.DC_EVENT_IMAP_CONNECTED) == 2
|
assert sig(const.DC_EVENT_SMTP_CONNECTED)
|
||||||
assert sig(const.DC_EVENT_SMTP_MESSAGE_SENT) == 2
|
assert sig(const.DC_EVENT_IMAP_CONNECTED)
|
||||||
|
assert sig(const.DC_EVENT_SMTP_MESSAGE_SENT)
|
||||||
|
assert sig(const.DC_EVENT_IMEX_FILE_WRITTEN)
|
||||||
|
|
||||||
|
|
||||||
def test_markseen_invalid_message_ids(acfactory):
|
def test_markseen_invalid_message_ids(acfactory):
|
||||||
ac1 = acfactory.get_configured_offline_account()
|
ac1 = acfactory.get_configured_offline_account()
|
||||||
contact1 = ac1.create_contact(email="some1@example.com", name="some1")
|
|
||||||
chat = ac1.create_chat_by_contact(contact1)
|
contact1 = ac1.create_contact("some1@example.com", name="some1")
|
||||||
|
chat = contact1.create_chat()
|
||||||
chat.send_text("one messae")
|
chat.send_text("one messae")
|
||||||
ac1._evlogger.get_matching("DC_EVENT_MSGS_CHANGED")
|
ac1._evtracker.get_matching("DC_EVENT_MSGS_CHANGED")
|
||||||
msg_ids = [9]
|
msg_ids = [9]
|
||||||
lib.dc_markseen_msgs(ac1._dc_context, msg_ids, len(msg_ids))
|
lib.dc_markseen_msgs(ac1._dc_context, msg_ids, len(msg_ids))
|
||||||
ac1._evlogger.ensure_event_not_queued("DC_EVENT_WARNING|DC_EVENT_ERROR")
|
ac1._evtracker.ensure_event_not_queued("DC_EVENT_WARNING|DC_EVENT_ERROR")
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_special_message_id_returns_empty_message(acfactory):
|
||||||
|
ac1 = acfactory.get_configured_offline_account()
|
||||||
|
for i in range(1, 10):
|
||||||
|
msg = ac1.get_message_by_id(i)
|
||||||
|
assert msg.id == 0
|
||||||
|
|
||||||
|
|
||||||
|
def test_provider_info_none():
|
||||||
|
ctx = ffi.gc(
|
||||||
|
lib.dc_context_new(ffi.NULL, ffi.NULL, ffi.NULL),
|
||||||
|
lib.dc_context_unref,
|
||||||
|
)
|
||||||
|
assert lib.dc_provider_new_from_email(ctx, cutil.as_dc_charpointer("email@unexistent.no")) == ffi.NULL
|
||||||
|
|
||||||
|
|
||||||
|
def test_get_info_open(tmpdir):
|
||||||
|
db_fname = tmpdir.join("test.db")
|
||||||
|
ctx = ffi.gc(
|
||||||
|
lib.dc_context_new(ffi.NULL, db_fname.strpath.encode("ascii"), ffi.NULL),
|
||||||
|
lib.dc_context_unref,
|
||||||
|
)
|
||||||
|
info = cutil.from_dc_charpointer(lib.dc_get_info(ctx))
|
||||||
|
assert 'deltachat_core_version' in info
|
||||||
|
assert 'database_dir' in info
|
||||||
|
|||||||
@@ -1,35 +1,39 @@
|
|||||||
[tox]
|
[tox]
|
||||||
# make sure to update environment list in travis.yml and appveyor.yml
|
# make sure to update environment list in travis.yml and appveyor.yml
|
||||||
envlist =
|
envlist =
|
||||||
py27
|
py37
|
||||||
py35
|
|
||||||
lint
|
lint
|
||||||
auditwheels
|
auditwheels
|
||||||
|
|
||||||
[testenv]
|
[testenv]
|
||||||
commands =
|
commands =
|
||||||
pytest -v -rsXx {posargs:tests}
|
pytest -n6 --reruns 2 --reruns-delay 5 -v -rsXx --ignored {posargs: tests examples}
|
||||||
python tests/package_wheels.py {toxworkdir}/wheelhouse
|
python tests/package_wheels.py {toxworkdir}/wheelhouse
|
||||||
passenv =
|
passenv =
|
||||||
TRAVIS
|
TRAVIS
|
||||||
DCC_RS_DEV
|
DCC_RS_DEV
|
||||||
DCC_RS_TARGET
|
DCC_RS_TARGET
|
||||||
DCC_PY_LIVECONFIG
|
DCC_PY_LIVECONFIG
|
||||||
|
DCC_NEW_TMP_EMAIL
|
||||||
|
CARGO_TARGET_DIR
|
||||||
|
RUSTC_WRAPPER
|
||||||
deps =
|
deps =
|
||||||
pytest
|
pytest
|
||||||
pytest-faulthandler
|
pytest-rerunfailures
|
||||||
|
pytest-timeout
|
||||||
|
pytest-xdist
|
||||||
pdbpp
|
pdbpp
|
||||||
requests
|
requests
|
||||||
|
|
||||||
[testenv:auditwheels]
|
[testenv:auditwheels]
|
||||||
skipsdist = True
|
skipsdist = True
|
||||||
|
deps = auditwheel
|
||||||
commands =
|
commands =
|
||||||
python tests/auditwheels.py {toxworkdir}/wheelhouse
|
python tests/auditwheels.py {toxworkdir}/wheelhouse
|
||||||
|
|
||||||
|
|
||||||
[testenv:lint]
|
[testenv:lint]
|
||||||
skipsdist = True
|
skipsdist = True
|
||||||
usedevelop = True
|
skip_install = True
|
||||||
deps =
|
deps =
|
||||||
flake8
|
flake8
|
||||||
# pygments required by rst-lint
|
# pygments required by rst-lint
|
||||||
@@ -37,26 +41,38 @@ deps =
|
|||||||
restructuredtext_lint
|
restructuredtext_lint
|
||||||
commands =
|
commands =
|
||||||
flake8 src/deltachat
|
flake8 src/deltachat
|
||||||
flake8 tests/
|
flake8 tests/ examples/
|
||||||
rst-lint --encoding 'utf-8' README.rst
|
rst-lint --encoding 'utf-8' README.rst
|
||||||
|
|
||||||
[testenv:doc]
|
[testenv:doc]
|
||||||
basepython = python3.5
|
changedir=doc
|
||||||
deps =
|
deps =
|
||||||
sphinx==2.0.1
|
sphinx
|
||||||
breathe
|
breathe
|
||||||
|
|
||||||
changedir = doc
|
|
||||||
commands =
|
commands =
|
||||||
sphinx-build -w docker-toxdoc-warnings.log -b html . _build/html
|
sphinx-build -Q -w toxdoc-warnings.log -b html . _build/html
|
||||||
|
|
||||||
|
|
||||||
|
[testenv:lintdoc]
|
||||||
|
skipsdist = True
|
||||||
|
usedevelop = True
|
||||||
|
deps =
|
||||||
|
{[testenv:lint]deps}
|
||||||
|
{[testenv:doc]deps}
|
||||||
|
commands =
|
||||||
|
{[testenv:lint]commands}
|
||||||
|
{[testenv:doc]commands}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[pytest]
|
[pytest]
|
||||||
addopts = -v -rs
|
addopts = -v -ra --strict-markers
|
||||||
python_files = tests/test_*.py
|
|
||||||
norecursedirs = .tox
|
norecursedirs = .tox
|
||||||
xfail_strict=true
|
xfail_strict=true
|
||||||
timeout = 60
|
timeout = 90
|
||||||
|
timeout_method = thread
|
||||||
|
markers =
|
||||||
|
ignored: ignore this test in default test runs, use --ignored to run.
|
||||||
|
|
||||||
[flake8]
|
[flake8]
|
||||||
max-line-length = 120
|
max-line-length = 120
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ if [ $? != 0 ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
pushd python
|
pushd python
|
||||||
if [ -e "./liveconfig" && -z "$DCC_PY_LIVECONFIG" ]; then
|
if [ -e "./liveconfig" -a -z "$DCC_PY_LIVECONFIG" ]; then
|
||||||
export DCC_PY_LIVECONFIG=liveconfig
|
export DCC_PY_LIVECONFIG=liveconfig
|
||||||
fi
|
fi
|
||||||
tox "$@"
|
tox "$@"
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
nightly-2019-08-13
|
1.43.1
|
||||||
|
|||||||
80
scripts/proxy.py
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
#!/usr/bin/env python3
|
||||||
|
# Examples:
|
||||||
|
#
|
||||||
|
# Original server that doesn't use SSL:
|
||||||
|
# ./proxy.py 8080 imap.nauta.cu 143
|
||||||
|
# ./proxy.py 8081 smtp.nauta.cu 25
|
||||||
|
#
|
||||||
|
# Original server that uses SSL:
|
||||||
|
# ./proxy.py 8080 testrun.org 993 --ssl
|
||||||
|
# ./proxy.py 8081 testrun.org 465 --ssl
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
import argparse
|
||||||
|
import selectors
|
||||||
|
import ssl
|
||||||
|
import socket
|
||||||
|
import socketserver
|
||||||
|
|
||||||
|
|
||||||
|
class Proxy(socketserver.ThreadingTCPServer):
|
||||||
|
allow_reuse_address = True
|
||||||
|
|
||||||
|
def __init__(self, proxy_host, proxy_port, real_host, real_port, use_ssl):
|
||||||
|
self.real_host = real_host
|
||||||
|
self.real_port = real_port
|
||||||
|
self.use_ssl = use_ssl
|
||||||
|
super().__init__((proxy_host, proxy_port), RequestHandler)
|
||||||
|
|
||||||
|
|
||||||
|
class RequestHandler(socketserver.BaseRequestHandler):
|
||||||
|
|
||||||
|
def handle(self):
|
||||||
|
print('{} - {} CONNECTED.'.format(datetime.now(), self.client_address))
|
||||||
|
|
||||||
|
total = 0
|
||||||
|
real_server = (self.server.real_host, self.server.real_port)
|
||||||
|
with socket.create_connection(real_server) as sock:
|
||||||
|
if self.server.use_ssl:
|
||||||
|
context = ssl.create_default_context()
|
||||||
|
sock = context.wrap_socket(
|
||||||
|
sock, server_hostname=real_server[0])
|
||||||
|
|
||||||
|
forward = {self.request: sock, sock: self.request}
|
||||||
|
|
||||||
|
sel = selectors.DefaultSelector()
|
||||||
|
sel.register(self.request, selectors.EVENT_READ,
|
||||||
|
self.client_address)
|
||||||
|
sel.register(sock, selectors.EVENT_READ, real_server)
|
||||||
|
|
||||||
|
active = True
|
||||||
|
while active:
|
||||||
|
events = sel.select()
|
||||||
|
for key, mask in events:
|
||||||
|
print('\n{} - {} wrote:'.format(datetime.now(), key.data))
|
||||||
|
data = key.fileobj.recv(1024)
|
||||||
|
received = len(data)
|
||||||
|
total += received
|
||||||
|
print(data)
|
||||||
|
print('{} Bytes\nTotal: {} Bytes'.format(received, total))
|
||||||
|
if data:
|
||||||
|
forward[key.fileobj].sendall(data)
|
||||||
|
else:
|
||||||
|
print('\nCLOSING CONNECTION.\n\n')
|
||||||
|
forward[key.fileobj].close()
|
||||||
|
key.fileobj.close()
|
||||||
|
active = False
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
p = argparse.ArgumentParser(description='Simple Python Proxy')
|
||||||
|
p.add_argument(
|
||||||
|
"proxy_port", help="the port where the proxy will listen", type=int)
|
||||||
|
p.add_argument('host', help="the real host")
|
||||||
|
p.add_argument('port', help="the port of the real host", type=int)
|
||||||
|
p.add_argument("--ssl", help="use ssl to connect to the real host",
|
||||||
|
action="store_true")
|
||||||
|
args = p.parse_args()
|
||||||
|
|
||||||
|
with Proxy('', args.proxy_port, args.host, args.port, args.ssl) as proxy:
|
||||||
|
proxy.serve_forever()
|
||||||
65
set_core_version.py
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import re
|
||||||
|
import pathlib
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
rex = re.compile(r'version = "(\S+)"')
|
||||||
|
|
||||||
|
def read_toml_version(relpath):
|
||||||
|
p = pathlib.Path(relpath)
|
||||||
|
assert p.exists()
|
||||||
|
for line in open(str(p)):
|
||||||
|
m = rex.match(line)
|
||||||
|
if m is not None:
|
||||||
|
return m.group(1)
|
||||||
|
raise ValueError("no version found in {}".format(relpath))
|
||||||
|
|
||||||
|
def replace_toml_version(relpath, newversion):
|
||||||
|
p = pathlib.Path(relpath)
|
||||||
|
assert p.exists()
|
||||||
|
tmp_path = str(p) + "_tmp"
|
||||||
|
with open(tmp_path, "w") as f:
|
||||||
|
for line in open(str(p)):
|
||||||
|
m = rex.match(line)
|
||||||
|
if m is not None:
|
||||||
|
f.write('version = "{}"\n'.format(newversion))
|
||||||
|
else:
|
||||||
|
f.write(line)
|
||||||
|
os.rename(tmp_path, str(p))
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
|
||||||
|
if len(sys.argv) < 2:
|
||||||
|
for x in ("Cargo.toml", "deltachat-ffi/Cargo.toml"):
|
||||||
|
print("{}: {}".format(x, read_toml_version(x)))
|
||||||
|
raise SystemExit("need argument: new version, example: 1.25.0")
|
||||||
|
newversion = sys.argv[1]
|
||||||
|
if newversion.count(".") < 2:
|
||||||
|
raise SystemExit("need at least two dots in version")
|
||||||
|
|
||||||
|
core_toml = read_toml_version("Cargo.toml")
|
||||||
|
ffi_toml = read_toml_version("deltachat-ffi/Cargo.toml")
|
||||||
|
assert core_toml == ffi_toml, (core_toml, ffi_toml)
|
||||||
|
|
||||||
|
for line in open("CHANGELOG.md"):
|
||||||
|
## 1.25.0
|
||||||
|
if line.startswith("## "):
|
||||||
|
if line[2:].strip().startswith(newversion):
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
raise SystemExit("CHANGELOG.md contains no entry for version: {}".format(newversion))
|
||||||
|
|
||||||
|
replace_toml_version("Cargo.toml", newversion)
|
||||||
|
replace_toml_version("deltachat-ffi/Cargo.toml", newversion)
|
||||||
|
|
||||||
|
subprocess.call(["cargo", "check"])
|
||||||
|
subprocess.call(["git", "add", "-u"])
|
||||||
|
# subprocess.call(["cargo", "update", "-p", "deltachat"])
|
||||||
|
|
||||||
|
print("after commit make sure to: ")
|
||||||
|
print("")
|
||||||
|
print(" git tag {}".format(newversion))
|
||||||
|
print("")
|
||||||
440
spec.md
Normal file
@@ -0,0 +1,440 @@
|
|||||||
|
# chat-mail specification
|
||||||
|
|
||||||
|
Version: 0.32.0
|
||||||
|
Status: In-progress
|
||||||
|
Format: [Semantic Line Breaks](https://sembr.org/)
|
||||||
|
|
||||||
|
This document roughly describes how chat-mail
|
||||||
|
apps use the standard e-mail system
|
||||||
|
to implement typical messenger functions.
|
||||||
|
|
||||||
|
- [Encryption](#encryption)
|
||||||
|
- [Outgoing messages](#outgoing-messages)
|
||||||
|
- [Incoming messages](#incoming-messages)
|
||||||
|
- [Forwarded messages](#forwarded-messages)
|
||||||
|
- [Groups](#groups)
|
||||||
|
- [Outgoing group messages](#outgoing-group-messages)
|
||||||
|
- [Incoming group messages](#incoming-group-messages)
|
||||||
|
- [Add and remove members](#add-and-remove-members)
|
||||||
|
- [Change group name](#change-group-name)
|
||||||
|
- [Set group image](#set-group-image)
|
||||||
|
- [Set profile image](#set-profile-image)
|
||||||
|
- [Locations](#locations)
|
||||||
|
- [User locations](#user-locations)
|
||||||
|
- [Points of interest](#points-of-interest)
|
||||||
|
- [Miscellaneous](#miscellaneous)
|
||||||
|
|
||||||
|
|
||||||
|
# Encryption
|
||||||
|
|
||||||
|
Messages SHOULD be encrypted by the
|
||||||
|
[Autocrypt](https://autocrypt.org/level1.html) standard;
|
||||||
|
`prefer-encrypt=mutual` MAY be set by default.
|
||||||
|
|
||||||
|
Meta data (at least the subject and all chat-headers) SHOULD be encrypted
|
||||||
|
by the [Protected Headers](https://www.ietf.org/id/draft-autocrypt-lamps-protected-headers-02.html) standard.
|
||||||
|
|
||||||
|
|
||||||
|
# Outgoing messages
|
||||||
|
|
||||||
|
Messengers MUST add a `Chat-Version: 1.0` header to outgoing messages.
|
||||||
|
For filtering and smart appearance of the messages in normal MUAs,
|
||||||
|
the `Subject` header SHOULD be `Message from <sender name>`.
|
||||||
|
Replies to messages MAY follow the typical `Re:`-format.
|
||||||
|
|
||||||
|
The body MAY contain text which MUST have the content type `text/plain`
|
||||||
|
or `mulipart/alternative` containing `text/plain`.
|
||||||
|
|
||||||
|
The text MAY be divided into a user-text-part and a footer-part using the
|
||||||
|
line `-- ` (minus, minus, space, lineend).
|
||||||
|
|
||||||
|
The user-text-part MUST contain only user generated content.
|
||||||
|
User generated content are eg. texts a user has actually typed
|
||||||
|
or pasted or forwarded from another user.
|
||||||
|
Full quotes, footers or sth. like that MUST NOT go to the user-text-part.
|
||||||
|
|
||||||
|
From: sender@domain
|
||||||
|
To: rcpt@domain
|
||||||
|
Chat-Version: 1.0
|
||||||
|
Content-Type: text/plain
|
||||||
|
Subject: Message from sender@domain
|
||||||
|
|
||||||
|
Hello world!
|
||||||
|
|
||||||
|
|
||||||
|
# Incoming messages
|
||||||
|
|
||||||
|
The `Chat-Version` header MAY be used
|
||||||
|
to detect if a messages comes from a compatible messenger.
|
||||||
|
|
||||||
|
The `Subject` header MUST NOT be used
|
||||||
|
to detect compatible messengers, groups or whatever.
|
||||||
|
|
||||||
|
Messenger SHOULD show the `Subject`
|
||||||
|
if the message comes from a normal MUA together with the email-body.
|
||||||
|
The email-body SHOULD be converted
|
||||||
|
to plain text, full-quotes and similar regions SHOULD be cut.
|
||||||
|
|
||||||
|
Attachments SHOULD be shown where possible.
|
||||||
|
If an attachment cannot be shown, a non-distracting warning SHOULD be printed.
|
||||||
|
|
||||||
|
|
||||||
|
# Forwarded messages
|
||||||
|
|
||||||
|
Forwarded messages are outgoing messages that contain a forwarded-header
|
||||||
|
before the user generated content.
|
||||||
|
|
||||||
|
The forwarded header MUST contain two lines:
|
||||||
|
The first line contains the text
|
||||||
|
`---------- Forwarded message ----------`
|
||||||
|
(10 minus, space, text `Forwarded message`, space, 10 minus).
|
||||||
|
The second line starts with `From: ` followed by the original sender
|
||||||
|
which SHOULD be anonymized or just a placeholder.
|
||||||
|
|
||||||
|
From: sender@domain
|
||||||
|
To: rcpt@domain
|
||||||
|
Chat-Version: 1.0
|
||||||
|
Content-Type: text/plain
|
||||||
|
Subject: Chat: Forwarded message
|
||||||
|
|
||||||
|
---------- Forwarded message ----------
|
||||||
|
From: Messenger
|
||||||
|
|
||||||
|
Hello world!
|
||||||
|
|
||||||
|
Incoming forwarded messages are detected by the header.
|
||||||
|
The messenger SHOULD mark these messages in a way that
|
||||||
|
it becomes obvious that the message is not created by the sender.
|
||||||
|
Note that most messengers do not show the original sender of forwarded messages
|
||||||
|
but MUAs typically expose the sender in the UI.
|
||||||
|
|
||||||
|
|
||||||
|
# Groups
|
||||||
|
|
||||||
|
Groups are chats with usually more than one recipient,
|
||||||
|
each defined by an email-address.
|
||||||
|
The sender plus the recipients are the group members.
|
||||||
|
All group members form the member list.
|
||||||
|
|
||||||
|
To allow different groups with the same members,
|
||||||
|
groups are identified by a group-id.
|
||||||
|
The group-id MUST be created only from the characters
|
||||||
|
`0`-`9`, `A`-`Z`, `a`-`z` `_` and `-`
|
||||||
|
and MUST have a length of at least 11 characters.
|
||||||
|
|
||||||
|
Groups MUST have a group-name.
|
||||||
|
The group-name is any non-zero-length UTF-8 string.
|
||||||
|
|
||||||
|
Groups MAY have a group-image.
|
||||||
|
|
||||||
|
|
||||||
|
## Outgoing groups messages
|
||||||
|
|
||||||
|
All group members MUST be added to the `From`/`To` headers.
|
||||||
|
The group-id MUST be written to the `Chat-Group-ID` header.
|
||||||
|
The group-name MUST be written to `Chat-Group-Name` header
|
||||||
|
(the forced presence of this header makes it easier
|
||||||
|
to join a group chat on a second device any time).
|
||||||
|
|
||||||
|
The `Subject` header of outgoing group messages
|
||||||
|
SHOULD be set to the group-name.
|
||||||
|
|
||||||
|
To identify the group-id on replies from normal MUAs,
|
||||||
|
the group-id MUST also be added to the message-id of outgoing messages.
|
||||||
|
The message-id MUST have the format `Gr.<group-id>.<unique data>`.
|
||||||
|
|
||||||
|
From: member1@domain
|
||||||
|
To: member2@domain, member3@domain
|
||||||
|
Chat-Version: 1.0
|
||||||
|
Chat-Group-ID: 12345uvwxyZ
|
||||||
|
Chat-Group-Name: My Group
|
||||||
|
Message-ID: Gr.12345uvwxyZ.0001@domain
|
||||||
|
Subject: Chat: My Group: Hello group ...
|
||||||
|
|
||||||
|
Hello group - this group contains three members
|
||||||
|
|
||||||
|
Messengers adding the member list in the form `Name <email-address>`
|
||||||
|
MUST take care only to distribute the names authorized by the contacts themselves.
|
||||||
|
Otherwise, names as _Daddy_ or _Honey_ may be distributed
|
||||||
|
(this issue is also true for normal MUAs, however,
|
||||||
|
for more contact- and chat-centralized apps
|
||||||
|
such situations happen more frequently).
|
||||||
|
|
||||||
|
|
||||||
|
## Incoming group messages
|
||||||
|
|
||||||
|
The messenger MUST search incoming messages for the group-id
|
||||||
|
in the following headers: `Chat-Group-ID`,
|
||||||
|
`Message-ID`, `In-Reply-To` and `References` (in this order).
|
||||||
|
|
||||||
|
If the messenger finds a valid and existent group-id,
|
||||||
|
the message SHOULD be assigned to the given group.
|
||||||
|
If the messenger finds a valid but not existent group-id,
|
||||||
|
the messenger MAY create a new group.
|
||||||
|
If no group-id is found,
|
||||||
|
the message MAY be assigned
|
||||||
|
to a normal single-user chat with the email-address given in `From`.
|
||||||
|
|
||||||
|
|
||||||
|
## Add and remove members
|
||||||
|
|
||||||
|
Messenger clients MUST init the member list
|
||||||
|
from the `From`/`To` headers on the first group message.
|
||||||
|
|
||||||
|
When a member is added later,
|
||||||
|
a `Chat-Group-Member-Added` action header must be sent
|
||||||
|
with the value set to the email-address of the added member.
|
||||||
|
When receiving a `Chat-Group-Member-Added` header, however,
|
||||||
|
_all missing_ members the `From`/`To` headers has to be added.
|
||||||
|
This is to mitigate problems when receiving messages
|
||||||
|
in different orders, esp. on creating new groups.
|
||||||
|
|
||||||
|
To remove a member, a `Chat-Group-Member-Removed` header must be sent
|
||||||
|
with the value set to the email-address of the member to remove.
|
||||||
|
When receiving a `Chat-Group-Member-Removed` header,
|
||||||
|
only exaxtly the given member has to be removed from the member list.
|
||||||
|
|
||||||
|
Messenger clients MUST NOT construct the member list
|
||||||
|
on other group messages
|
||||||
|
(this is to avoid accidentally altered To-lists in normal MUAs;
|
||||||
|
the user does not expect adding a user to a _message_
|
||||||
|
will also add him to the _group_ "forever").
|
||||||
|
|
||||||
|
The messenger SHOULD send an explicit mail for each added or removed member.
|
||||||
|
The body of the message SHOULD contain
|
||||||
|
a localized description about what happened
|
||||||
|
and the message SHOULD appear as a message or action from the sender.
|
||||||
|
|
||||||
|
From: member1@domain
|
||||||
|
To: member2@domain, member3@domain, member4@domain
|
||||||
|
Chat-Version: 1.0
|
||||||
|
Chat-Group-ID: 12345uvwxyZ
|
||||||
|
Chat-Group-Name: My Group
|
||||||
|
Chat-Group-Member-Added: member4@domain
|
||||||
|
Message-ID: Gr.12345uvwxyZ.0002@domain
|
||||||
|
Subject: Chat: My Group: Hello, ...
|
||||||
|
|
||||||
|
Hello, I've added member4@domain to our group. Now we have 4 members.
|
||||||
|
|
||||||
|
To remove a member:
|
||||||
|
|
||||||
|
From: member1@domain
|
||||||
|
To: member2@domain, member3@domain
|
||||||
|
Chat-Version: 1.0
|
||||||
|
Chat-Group-ID: 12345uvwxyZ
|
||||||
|
Chat-Group-Name: My Group
|
||||||
|
Chat-Group-Member-Removed: member4@domain
|
||||||
|
Message-ID: Gr.12345uvwxyZ.0003@domain
|
||||||
|
Subject: Chat: My Group: Hello, ...
|
||||||
|
|
||||||
|
Hello, I've removed member4@domain from our group. Now we have 3 members.
|
||||||
|
|
||||||
|
|
||||||
|
## Change group name
|
||||||
|
|
||||||
|
To change the group-name,
|
||||||
|
the messenger MUST send the action header `Chat-Group-Name-Changed`
|
||||||
|
with the value set to the old group name to all group members.
|
||||||
|
The new group name goes to the header `Chat-Group-Name`.
|
||||||
|
|
||||||
|
The messenger SHOULD send an explicit mail for each name change.
|
||||||
|
The body of the message SHOULD contain
|
||||||
|
a localized description about what happened
|
||||||
|
and the message SHOULD appear as a message or action from the sender.
|
||||||
|
|
||||||
|
From: member1@domain
|
||||||
|
To: member2@domain, member3@domain
|
||||||
|
Chat-Version: 1.0
|
||||||
|
Chat-Group-ID: 12345uvwxyZ
|
||||||
|
Chat-Group-Name: Our Group
|
||||||
|
Chat-Group-Name-Changed: My Group
|
||||||
|
Message-ID: Gr.12345uvwxyZ.0004@domain
|
||||||
|
Subject: Chat: Our Group: Hello, ...
|
||||||
|
|
||||||
|
Hello, I've changed the group name from "My Group" to "Our Group".
|
||||||
|
|
||||||
|
|
||||||
|
## Set group image
|
||||||
|
|
||||||
|
A group MAY have a group-image.
|
||||||
|
To change or set the group-image,
|
||||||
|
the messenger MUST attach an image file to a message
|
||||||
|
and MUST add the header `Chat-Group-Avatar`
|
||||||
|
with the value set to the image name.
|
||||||
|
|
||||||
|
To remove the group-image,
|
||||||
|
the messenger MUST add the header `Chat-Group-Avatar: 0`.
|
||||||
|
|
||||||
|
The messenger SHOULD send an explicit mail for each group image change.
|
||||||
|
The body of the message SHOULD contain
|
||||||
|
a localized description about what happened
|
||||||
|
and the message SHOULD appear as a message or action from the sender.
|
||||||
|
|
||||||
|
|
||||||
|
From: member1@domain
|
||||||
|
To: member2@domain, member3@domain
|
||||||
|
Chat-Version: 1.0
|
||||||
|
Chat-Group-ID: 12345uvwxyZ
|
||||||
|
Chat-Group-Name: Our Group
|
||||||
|
Chat-Group-Avatar: image.jpg
|
||||||
|
Message-ID: Gr.12345uvwxyZ.0005@domain
|
||||||
|
Subject: Chat: Our Group: Hello, ...
|
||||||
|
Content-Type: multipart/mixed; boundary="==break=="
|
||||||
|
|
||||||
|
--==break==
|
||||||
|
Content-Type: text/plain
|
||||||
|
|
||||||
|
Hello, I've changed the group image.
|
||||||
|
--==break==
|
||||||
|
Content-Type: image/jpeg
|
||||||
|
Content-Disposition: attachment; filename="image.jpg"
|
||||||
|
|
||||||
|
/9j/4AAQSkZJRgABAQAAAQABAAD/2wBDAAYEBQYFBAYGBQYHBw ...
|
||||||
|
--==break==--
|
||||||
|
|
||||||
|
The image format SHOULD be image/jpeg or image/png.
|
||||||
|
To save data, it is RECOMMENDED
|
||||||
|
to add a `Chat-Group-Avatar` only on image changes.
|
||||||
|
|
||||||
|
|
||||||
|
# Set profile image
|
||||||
|
|
||||||
|
A user MAY have a profile-image that MAY be distributed to their contacts.
|
||||||
|
To change or set the profile-image,
|
||||||
|
the messenger MUST attach an image file to a message
|
||||||
|
and MUST add the header `Chat-User-Avatar`
|
||||||
|
with the value set to the image name.
|
||||||
|
|
||||||
|
To remove the profile-image,
|
||||||
|
the messenger MUST add the header `Chat-User-Avatar: 0`.
|
||||||
|
|
||||||
|
To distribute the image,
|
||||||
|
the messenger MAY send the profile image
|
||||||
|
together with the next mail to a given contact
|
||||||
|
(to do this only once,
|
||||||
|
the messenger has to keep a `user_avatar_update_state` somewhere).
|
||||||
|
Alternatively, the messenger MAY send an explicit mail
|
||||||
|
for each profile-image change to all contacts using a compatible messenger.
|
||||||
|
The messenger SHOULD NOT send an explicit mail to normal MUAs.
|
||||||
|
|
||||||
|
From: sender@domain
|
||||||
|
To: rcpt@domain
|
||||||
|
Chat-Version: 1.0
|
||||||
|
Chat-User-Avatar: photo.jpg
|
||||||
|
Subject: Chat: Hello, ...
|
||||||
|
Content-Type: multipart/mixed; boundary="==break=="
|
||||||
|
|
||||||
|
--==break==
|
||||||
|
Content-Type: text/plain
|
||||||
|
|
||||||
|
Hello, I've changed my profile image.
|
||||||
|
--==break==
|
||||||
|
Content-Type: image/jpeg
|
||||||
|
Content-Disposition: attachment; filename="photo.jpg"
|
||||||
|
|
||||||
|
AKCgkJi3j4l5kjoldfUAKCgkJi3j4lldfHjgWICwgIEBQYFBA ...
|
||||||
|
--==break==--
|
||||||
|
|
||||||
|
The image format SHOULD be image/jpeg or image/png.
|
||||||
|
Note that `Chat-User-Avatar` may appear together with all other headers,
|
||||||
|
eg. there may be a `Chat-User-Avatar` and a `Chat-Group-Avatar` header
|
||||||
|
in the same message.
|
||||||
|
To save data, it is RECOMMENDED to add a `Chat-User-Avatar` header
|
||||||
|
only on image changes.
|
||||||
|
|
||||||
|
|
||||||
|
# Locations
|
||||||
|
|
||||||
|
Locations can be attachted to messages using
|
||||||
|
[standard kml-files](https://www.opengeospatial.org/standards/kml/)
|
||||||
|
with well-known names.
|
||||||
|
|
||||||
|
|
||||||
|
## User locations
|
||||||
|
|
||||||
|
To send the location of the sender,
|
||||||
|
the app can attach a file with the name `location.kml`.
|
||||||
|
The file can contain one or more locations.
|
||||||
|
Apps that support location streaming will typically collect some location events
|
||||||
|
and send them together in one file.
|
||||||
|
As each location has an independent timestamp,
|
||||||
|
the apps can show the location as a track.
|
||||||
|
|
||||||
|
Note that the `addr` attribute inside the `location.kml` file
|
||||||
|
MUST match the users email-address.
|
||||||
|
Otherwise, the file is discarded silently;
|
||||||
|
this is to protect against getting wrong locations,
|
||||||
|
eg. forwarded from a normal MUA.
|
||||||
|
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<kml xmlns="http://www.opengis.net/kml/2.2">
|
||||||
|
<Document addr="ndh@deltachat.de">
|
||||||
|
<Placemark>
|
||||||
|
<Timestamp><when>2020-01-11T20:40:19Z</when></Timestamp>
|
||||||
|
<Point><coordinates accuracy="1.2">1.234,5.678</coordinates></Point>
|
||||||
|
</Placemark>
|
||||||
|
<Placemark>
|
||||||
|
<Timestamp><when>2020-01-11T20:40:25Z</when></Timestamp>
|
||||||
|
<Point><coordinates accuracy="5.4">7.654,3.21</coordinates></Point>
|
||||||
|
</Placemark>
|
||||||
|
</Document>
|
||||||
|
</kml>
|
||||||
|
|
||||||
|
|
||||||
|
## Points of interest
|
||||||
|
|
||||||
|
To send an "Point of interest", a POI,
|
||||||
|
use a normal message and attach a file with the name `message.kml`.
|
||||||
|
In contrast to user locations, this file should contain only one location
|
||||||
|
and an address-attribute is not needed -
|
||||||
|
as the location belongs to the message content,
|
||||||
|
it is fine if the location is detected on forwarding etc.
|
||||||
|
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<kml xmlns="http://www.opengis.net/kml/2.2">
|
||||||
|
<Document>
|
||||||
|
<Placemark>
|
||||||
|
<Timestamp><when>2020-01-01T20:40:19Z</when></Timestamp>
|
||||||
|
<Point><coordinates accuracy="1.2">1.234,5.678</coordinates></Point>
|
||||||
|
</Placemark>
|
||||||
|
</Document>
|
||||||
|
</kml>
|
||||||
|
|
||||||
|
|
||||||
|
# Miscellaneous
|
||||||
|
|
||||||
|
Messengers SHOULD use the header `In-Reply-To` as usual.
|
||||||
|
|
||||||
|
Messengers SHOULD add a `Chat-Voice-message: 1` header
|
||||||
|
if an attached audio file is a voice message.
|
||||||
|
|
||||||
|
Messengers MAY add a `Chat-Duration` header
|
||||||
|
to specify the duration of attached audio or video files.
|
||||||
|
The value MUST be the duration in milliseconds.
|
||||||
|
This allows the receiver to show the time without knowing the file format.
|
||||||
|
|
||||||
|
In-Reply-To: Gr.12345uvwxyZ.0005@domain
|
||||||
|
Chat-Voice-Message: 1
|
||||||
|
Chat-Duration: 10000
|
||||||
|
|
||||||
|
Messengers MAY send and receive Message Disposition Notifications
|
||||||
|
(MDNs, [RFC 8098](https://tools.ietf.org/html/rfc8098),
|
||||||
|
[RFC 3503](https://tools.ietf.org/html/rfc3503))
|
||||||
|
using the `Chat-Disposition-Notification-To` header
|
||||||
|
instead of the `Disposition-Notification-To`
|
||||||
|
(which unfortunately forces many other MUAs
|
||||||
|
to send weird mails not following any standard).
|
||||||
|
|
||||||
|
|
||||||
|
## Sync messages
|
||||||
|
|
||||||
|
If some action is required by a message header,
|
||||||
|
the action should only be performed if the _effective date_ is newer
|
||||||
|
than the date the last action was performed.
|
||||||
|
|
||||||
|
We define the effective date of a message
|
||||||
|
as the sending time of the message as indicated by its Date header,
|
||||||
|
or the time of first receipt if that date is in the future or unavailable.
|
||||||
|
|
||||||
|
|
||||||
|
Copyright © 2017-2020 Delta Chat contributors.
|
||||||
236
src/aheader.rs
@@ -1,17 +1,20 @@
|
|||||||
|
//! # Autocrypt header module
|
||||||
|
//!
|
||||||
|
//! Parse and create [Autocrypt-headers](https://autocrypt.org/en/latest/level1.html#the-autocrypt-header).
|
||||||
|
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::ffi::CStr;
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::{fmt, str};
|
use std::{fmt, str};
|
||||||
|
|
||||||
use mmime::mailimf_types::*;
|
use deltachat_derive::*;
|
||||||
|
|
||||||
use crate::constants::*;
|
|
||||||
use crate::contact::*;
|
use crate::contact::*;
|
||||||
use crate::dc_tools::as_str;
|
use crate::context::Context;
|
||||||
use crate::key::*;
|
use crate::headerdef::{HeaderDef, HeaderDefMap};
|
||||||
|
use crate::key::{DcKey, SignedPublicKey};
|
||||||
|
|
||||||
/// Possible values for encryption preference
|
/// Possible values for encryption preference
|
||||||
#[derive(PartialEq, Eq, Debug, Clone, Copy, FromPrimitive, ToPrimitive)]
|
#[derive(PartialEq, Eq, Debug, Clone, Copy, FromPrimitive, ToPrimitive, Sqlx)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum EncryptPreference {
|
pub enum EncryptPreference {
|
||||||
NoPreference = 0,
|
NoPreference = 0,
|
||||||
@@ -41,22 +44,27 @@ impl str::FromStr for EncryptPreference {
|
|||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
match s {
|
match s {
|
||||||
"mutual" => Ok(EncryptPreference::Mutual),
|
"mutual" => Ok(EncryptPreference::Mutual),
|
||||||
"reset" => Ok(EncryptPreference::Reset),
|
"nopreference" => Ok(EncryptPreference::NoPreference),
|
||||||
_ => Ok(EncryptPreference::NoPreference),
|
_ => Err(()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse and create [Autocrypt-headers](https://autocrypt.org/en/latest/level1.html#the-autocrypt-header).
|
/// Autocrypt header
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Aheader {
|
pub struct Aheader {
|
||||||
pub addr: String,
|
pub addr: String,
|
||||||
pub public_key: Key,
|
pub public_key: SignedPublicKey,
|
||||||
pub prefer_encrypt: EncryptPreference,
|
pub prefer_encrypt: EncryptPreference,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Aheader {
|
impl Aheader {
|
||||||
pub fn new(addr: String, public_key: Key, prefer_encrypt: EncryptPreference) -> Self {
|
/// Creates new autocrypt header
|
||||||
|
pub fn new(
|
||||||
|
addr: String,
|
||||||
|
public_key: SignedPublicKey,
|
||||||
|
prefer_encrypt: EncryptPreference,
|
||||||
|
) -> Self {
|
||||||
Aheader {
|
Aheader {
|
||||||
addr,
|
addr,
|
||||||
public_key,
|
public_key,
|
||||||
@@ -64,69 +72,52 @@ impl Aheader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_imffields(
|
pub fn from_headers(
|
||||||
wanted_from: *const libc::c_char,
|
context: &Context,
|
||||||
header: *const mailimf_fields,
|
wanted_from: &str,
|
||||||
|
headers: &[mailparse::MailHeader<'_>],
|
||||||
) -> Option<Self> {
|
) -> Option<Self> {
|
||||||
if wanted_from.is_null() || header.is_null() {
|
if let Some(value) = headers.get_header_value(HeaderDef::Autocrypt) {
|
||||||
return None;
|
match Self::from_str(&value) {
|
||||||
}
|
Ok(header) => {
|
||||||
|
if addr_cmp(&header.addr, wanted_from) {
|
||||||
let mut fine_header = None;
|
return Some(header);
|
||||||
let mut cur = unsafe { (*(*header).fld_list).first };
|
|
||||||
|
|
||||||
while !cur.is_null() {
|
|
||||||
let field = unsafe { (*cur).data as *mut mailimf_field };
|
|
||||||
if !field.is_null()
|
|
||||||
&& unsafe { (*field).fld_type } == MAILIMF_FIELD_OPTIONAL_FIELD as libc::c_int
|
|
||||||
{
|
|
||||||
let optional_field = unsafe { (*field).fld_data.fld_optional_field };
|
|
||||||
if !optional_field.is_null()
|
|
||||||
&& unsafe { !(*optional_field).fld_name.is_null() }
|
|
||||||
&& unsafe { CStr::from_ptr((*optional_field).fld_name).to_str().unwrap() }
|
|
||||||
== "Autocrypt"
|
|
||||||
{
|
|
||||||
let value = unsafe {
|
|
||||||
CStr::from_ptr((*optional_field).fld_value)
|
|
||||||
.to_str()
|
|
||||||
.unwrap()
|
|
||||||
};
|
|
||||||
|
|
||||||
match Self::from_str(value) {
|
|
||||||
Ok(test) => {
|
|
||||||
if addr_cmp(&test.addr, as_str(wanted_from)) {
|
|
||||||
if fine_header.is_none() {
|
|
||||||
fine_header = Some(test);
|
|
||||||
} else {
|
|
||||||
// TODO: figure out what kind of error case this is
|
|
||||||
return None;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
Err(err) => {
|
||||||
_ => {}
|
warn!(
|
||||||
|
context,
|
||||||
|
"found invalid autocrypt header {}: {:?}", value, err
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = unsafe { (*cur).next };
|
None
|
||||||
}
|
|
||||||
|
|
||||||
fine_header
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for Aheader {
|
impl fmt::Display for Aheader {
|
||||||
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
|
||||||
// TODO replace 78 with enum /rtn
|
write!(fmt, "addr={};", self.addr)?;
|
||||||
// adds a whitespace every 78 characters, this allows libEtPan to
|
if self.prefer_encrypt == EncryptPreference::Mutual {
|
||||||
// wrap the lines according to RFC 5322
|
write!(fmt, " prefer-encrypt=mutual;")?;
|
||||||
|
}
|
||||||
|
|
||||||
|
// adds a whitespace every 78 characters, this allows
|
||||||
|
// email crate to wrap the lines according to RFC 5322
|
||||||
// (which may insert a linebreak before every whitespace)
|
// (which may insert a linebreak before every whitespace)
|
||||||
let keydata = self.public_key.to_base64(78);
|
let keydata = self.public_key.to_base64().chars().enumerate().fold(
|
||||||
write!(
|
String::new(),
|
||||||
fmt,
|
|mut res, (i, c)| {
|
||||||
"addr={}; prefer-encrypt={}; keydata={}",
|
if i % 78 == 78 - "keydata=".len() {
|
||||||
self.addr, self.prefer_encrypt, keydata
|
res.push(' ')
|
||||||
)
|
}
|
||||||
|
res.push(c);
|
||||||
|
res
|
||||||
|
},
|
||||||
|
);
|
||||||
|
write!(fmt, " keydata={}", keydata)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,17 +126,13 @@ impl str::FromStr for Aheader {
|
|||||||
|
|
||||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||||
let mut attributes: BTreeMap<String, String> = s
|
let mut attributes: BTreeMap<String, String> = s
|
||||||
.split(";")
|
.split(';')
|
||||||
.filter_map(|a| {
|
.filter_map(|a| {
|
||||||
let attribute: Vec<&str> = a.trim().splitn(2, "=").collect();
|
let attribute: Vec<&str> = a.trim().splitn(2, '=').collect();
|
||||||
if attribute.len() < 2 {
|
match &attribute[..] {
|
||||||
return None;
|
[key, value] => Some((key.trim().to_string(), value.trim().to_string())),
|
||||||
|
_ => None,
|
||||||
}
|
}
|
||||||
|
|
||||||
Some((
|
|
||||||
attribute[0].trim().to_string(),
|
|
||||||
attribute[1].trim().to_string(),
|
|
||||||
))
|
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
@@ -155,34 +142,20 @@ impl str::FromStr for Aheader {
|
|||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
let public_key: SignedPublicKey = attributes
|
||||||
let public_key = match attributes
|
|
||||||
.remove("keydata")
|
.remove("keydata")
|
||||||
.and_then(|raw| Key::from_base64(&raw, KeyType::Public))
|
.ok_or(())
|
||||||
{
|
.and_then(|raw| SignedPublicKey::from_base64(&raw).or(Err(())))
|
||||||
Some(key) => {
|
.and_then(|key| key.verify().and(Ok(key)).or(Err(())))?;
|
||||||
if key.verify() {
|
|
||||||
key
|
|
||||||
} else {
|
|
||||||
return Err(());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
None => {
|
|
||||||
return Err(());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
let prefer_encrypt = match attributes
|
let prefer_encrypt = attributes
|
||||||
.remove("prefer-encrypt")
|
.remove("prefer-encrypt")
|
||||||
.and_then(|raw| raw.parse().ok())
|
.and_then(|raw| raw.parse().ok())
|
||||||
{
|
.unwrap_or_default();
|
||||||
Some(pref) => pref,
|
|
||||||
None => EncryptPreference::NoPreference,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Autocrypt-Level0: unknown attributes starting with an underscore can be safely ignored
|
// Autocrypt-Level0: unknown attributes starting with an underscore can be safely ignored
|
||||||
// Autocrypt-Level0: unknown attribute, treat the header as invalid
|
// Autocrypt-Level0: unknown attribute, treat the header as invalid
|
||||||
if attributes.keys().find(|k| !k.starts_with("_")).is_some() {
|
if attributes.keys().any(|k| !k.starts_with('_')) {
|
||||||
return Err(());
|
return Err(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -198,15 +171,13 @@ impl str::FromStr for Aheader {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
fn rawkey() -> String {
|
const RAWKEY: &str = "xsBNBFzG3j0BCAC6iNhT8zydvCXi8LI/gFnkadMbfmSE/rTJskRRra/utGbLyDta/yTrJgWL7O3y/g4HdDW/dN2z26Y6W13IMzx9gLInn1KQZChtqWAcr/ReUucXcymwcfg1mdkBGk3TSLeLihN6CJx8Wsv8ig+kgAzte4f5rqEEAJVQ9WZHuti7UiYs6oRzqTo06CRe9owVXxzdMf0VDQtf7ZFm9dpzKKbhH7Lu8880iiotQ9/yRCkDGp9fNThsrLdZiK6OIAcIBAqi2rI89aS1dAmnRbktQieCx5izzyYkR1KvVL3gTTllHOzfKVEC2asmtWu2e4se/+O4WMIS1eGrn7GeWVb0Vwc5ABEBAAHNETxhQEBiLmV4YW1wbGUuZGU+wsCJBBABCAAzAhkBBQJcxt5FAhsDBAsJCAcGFQgJCgsCAxYCARYhBI4xxYKBgH3ANh5cufaKrc9mtiMLAAoJEPaKrc9mtiML938H/18F+3Wf9/JaAy/8hCO1v4S2PVBhxaKCokaNFtkfaMRne2l087LscCFPiFNyb4mv6Z3YeK8Xpxlp2sI0ecvdiqLUOGfnxS6tQrj+83EjtIrZ/hXOk1h121QFWH9Zg2VNHtODXjAgdLDC0NWUrclR0ZOqEDQHeo0ibTILdokVfXFN25wakPmGaYJP2y729cb1ve7RzvIvwn+Dddfxo3ao72rBfLi7l4NQ4S0KsY4cw+/6l5bRCKYCP77wZtvCwUvfVVosLdT43agtSiBI49+ayqvZ8OCvSJa61i+v81brTiEy9GBod4eAp45Ibsuemkw+gon4ZOvUXHTjwFB+h63MrozOwE0EXMbePQEIAL/vauf1zK8JgCu3V+G+SOX0iWw5xUlCPX+ERpBbWfwu3uAqn4wYXD3JDE/fVAF668xiV4eTPtlSUd5h0mn+G7uXMMOtkb+20SoEt50f8zw8TrL9t+ZsV11GKZWJpCar5AhXWsn6EEi8I2hLL5vn55ZZmHuGgN4jjmkRl3ToKCLhaXwTBjCJem7N5EH7F75wErEITa55v4Lb4Nfca7vnvtYrI1OA446xa8gHra0SINelTD09/JM/Fw4sWVPBaRZmJK/Tnu79N23No9XBUubmFPv1pNexZsQclicnTpt/BEWhiun7d6lfGB63K1aoHRTR1pcrWvBuALuuz0gqar2zlI0AEQEAAcLAdgQYAQgAIAUCXMbeRQIbDBYhBI4xxYKBgH3ANh5cufaKrc9mtiMLAAoJEPaKrc9mtiMLKSEIAIyLCRO2OyZ0IYRvRPpMn4p7E+7Pfcz/0mSkOy+1hshgJnqivXurm8zwGrwdMqeV4eslKR9H1RUdWGUQJNbtwmmjrt5DHpIhYHl5t3FpCBaGbV20Omo00Q38lBl9MtrmZkZw+ktEk6X+0xCKssMF+2MADkSOIufbR5HrDVB89VZOHCO9DeXvCUUAw2hyJiL/LHmLzJ40zYoTmb+F//f0k0j+tRdbkefyRoCmwG7YGiT+2hnCdgcezswnzah5J3ZKlrg7jOGo1LxtbvNUzxNBbC6S/aNgwm6qxo7xegRhmEl5uZ16zwyj4qz+xkjGy25Of5mWfUDoNw7OT7sjUbHOOMc=";
|
||||||
"xsBNBFzG3j0BCAC6iNhT8zydvCXi8LI/gFnkadMbfmSE/rTJskRRra/utGbLyDta/yTrJgWL7O3y/g4HdDW/dN2z26Y6W13IMzx9gLInn1KQZChtqWAcr/ReUucXcymwcfg1mdkBGk3TSLeLihN6CJx8Wsv8ig+kgAzte4f5rqEEAJVQ9WZHuti7UiYs6oRzqTo06CRe9owVXxzdMf0VDQtf7ZFm9dpzKKbhH7Lu8880iiotQ9/yRCkDGp9fNThsrLdZiK6OIAcIBAqi2rI89aS1dAmnRbktQieCx5izzyYkR1KvVL3gTTllHOzfKVEC2asmtWu2e4se/+O4WMIS1eGrn7GeWVb0Vwc5ABEBAAHNETxhQEBiLmV4YW1wbGUuZGU+wsCJBBABCAAzAhkBBQJcxt5FAhsDBAsJCAcGFQgJCgsCAxYCARYhBI4xxYKBgH3ANh5cufaKrc9mtiMLAAoJEPaKrc9mtiML938H/18F+3Wf9/JaAy/8hCO1v4S2PVBhxaKCokaNFtkfaMRne2l087LscCFPiFNyb4mv6Z3YeK8Xpxlp2sI0ecvdiqLUOGfnxS6tQrj+83EjtIrZ/hXOk1h121QFWH9Zg2VNHtODXjAgdLDC0NWUrclR0ZOqEDQHeo0ibTILdokVfXFN25wakPmGaYJP2y729cb1ve7RzvIvwn+Dddfxo3ao72rBfLi7l4NQ4S0KsY4cw+/6l5bRCKYCP77wZtvCwUvfVVosLdT43agtSiBI49+ayqvZ8OCvSJa61i+v81brTiEy9GBod4eAp45Ibsuemkw+gon4ZOvUXHTjwFB+h63MrozOwE0EXMbePQEIAL/vauf1zK8JgCu3V+G+SOX0iWw5xUlCPX+ERpBbWfwu3uAqn4wYXD3JDE/fVAF668xiV4eTPtlSUd5h0mn+G7uXMMOtkb+20SoEt50f8zw8TrL9t+ZsV11GKZWJpCar5AhXWsn6EEi8I2hLL5vn55ZZmHuGgN4jjmkRl3ToKCLhaXwTBjCJem7N5EH7F75wErEITa55v4Lb4Nfca7vnvtYrI1OA446xa8gHra0SINelTD09/JM/Fw4sWVPBaRZmJK/Tnu79N23No9XBUubmFPv1pNexZsQclicnTpt/BEWhiun7d6lfGB63K1aoHRTR1pcrWvBuALuuz0gqar2zlI0AEQEAAcLAdgQYAQgAIAUCXMbeRQIbDBYhBI4xxYKBgH3ANh5cufaKrc9mtiMLAAoJEPaKrc9mtiMLKSEIAIyLCRO2OyZ0IYRvRPpMn4p7E+7Pfcz/0mSkOy+1hshgJnqivXurm8zwGrwdMqeV4eslKR9H1RUdWGUQJNbtwmmjrt5DHpIhYHl5t3FpCBaGbV20Omo00Q38lBl9MtrmZkZw+ktEk6X+0xCKssMF+2MADkSOIufbR5HrDVB89VZOHCO9DeXvCUUAw2hyJiL/LHmLzJ40zYoTmb+F//f0k0j+tRdbkefyRoCmwG7YGiT+2hnCdgcezswnzah5J3ZKlrg7jOGo1LxtbvNUzxNBbC6S/aNgwm6qxo7xegRhmEl5uZ16zwyj4qz+xkjGy25Of5mWfUDoNw7OT7sjUbHOOMc=".into()
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_str() {
|
fn test_from_str() {
|
||||||
let h: Aheader = format!(
|
let h: Aheader = format!(
|
||||||
"addr=me@mail.com; prefer-encrypt=mutual; keydata={}",
|
"addr=me@mail.com; prefer-encrypt=mutual; keydata={}",
|
||||||
rawkey()
|
RAWKEY
|
||||||
)
|
)
|
||||||
.parse()
|
.parse()
|
||||||
.expect("failed to parse");
|
.expect("failed to parse");
|
||||||
@@ -215,9 +186,22 @@ mod tests {
|
|||||||
assert_eq!(h.prefer_encrypt, EncryptPreference::Mutual);
|
assert_eq!(h.prefer_encrypt, EncryptPreference::Mutual);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// EncryptPreference::Reset is an internal value, parser should never return it
|
||||||
|
#[test]
|
||||||
|
fn test_from_str_reset() {
|
||||||
|
let raw = format!(
|
||||||
|
"addr=reset@example.com; prefer-encrypt=reset; keydata={}",
|
||||||
|
RAWKEY
|
||||||
|
);
|
||||||
|
let h: Aheader = raw.parse().expect("failed to parse");
|
||||||
|
|
||||||
|
assert_eq!(h.addr, "reset@example.com");
|
||||||
|
assert_eq!(h.prefer_encrypt, EncryptPreference::NoPreference);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_str_non_critical() {
|
fn test_from_str_non_critical() {
|
||||||
let raw = format!("addr=me@mail.com; _foo=one; _bar=two; keydata={}", rawkey());
|
let raw = format!("addr=me@mail.com; _foo=one; _bar=two; keydata={}", RAWKEY);
|
||||||
let h: Aheader = raw.parse().expect("failed to parse");
|
let h: Aheader = raw.parse().expect("failed to parse");
|
||||||
|
|
||||||
assert_eq!(h.addr, "me@mail.com");
|
assert_eq!(h.addr, "me@mail.com");
|
||||||
@@ -228,33 +212,57 @@ mod tests {
|
|||||||
fn test_from_str_superflous_critical() {
|
fn test_from_str_superflous_critical() {
|
||||||
let raw = format!(
|
let raw = format!(
|
||||||
"addr=me@mail.com; _foo=one; _bar=two; other=me; keydata={}",
|
"addr=me@mail.com; _foo=one; _bar=two; other=me; keydata={}",
|
||||||
rawkey()
|
RAWKEY
|
||||||
);
|
);
|
||||||
assert!(raw.parse::<Aheader>().is_err());
|
assert!(raw.parse::<Aheader>().is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_good_headers() {
|
fn test_good_headers() {
|
||||||
let fixed_header = "addr=a@b.example.org; prefer-encrypt=mutual; keydata=xsBNBFzG3j0BCAC6iNhT8zydvCXi8LI/gFnkadMbfmSE/rTJskRRra/utGbLyDta/yTrJgWL7O3y/g 4HdDW/dN2z26Y6W13IMzx9gLInn1KQZChtqWAcr/ReUucXcymwcfg1mdkBGk3TSLeLihN6CJx8Wsv8 ig+kgAzte4f5rqEEAJVQ9WZHuti7UiYs6oRzqTo06CRe9owVXxzdMf0VDQtf7ZFm9dpzKKbhH7Lu88 80iiotQ9/yRCkDGp9fNThsrLdZiK6OIAcIBAqi2rI89aS1dAmnRbktQieCx5izzyYkR1KvVL3gTTll HOzfKVEC2asmtWu2e4se/+O4WMIS1eGrn7GeWVb0Vwc5ABEBAAHNETxhQEBiLmV4YW1wbGUuZGU+ws CJBBABCAAzAhkBBQJcxt5FAhsDBAsJCAcGFQgJCgsCAxYCARYhBI4xxYKBgH3ANh5cufaKrc9mtiML AAoJEPaKrc9mtiML938H/18F+3Wf9/JaAy/8hCO1v4S2PVBhxaKCokaNFtkfaMRne2l087LscCFPiF Nyb4mv6Z3YeK8Xpxlp2sI0ecvdiqLUOGfnxS6tQrj+83EjtIrZ/hXOk1h121QFWH9Zg2VNHtODXjAg dLDC0NWUrclR0ZOqEDQHeo0ibTILdokVfXFN25wakPmGaYJP2y729cb1ve7RzvIvwn+Dddfxo3ao72 rBfLi7l4NQ4S0KsY4cw+/6l5bRCKYCP77wZtvCwUvfVVosLdT43agtSiBI49+ayqvZ8OCvSJa61i+v 81brTiEy9GBod4eAp45Ibsuemkw+gon4ZOvUXHTjwFB+h63MrozOwE0EXMbePQEIAL/vauf1zK8JgC u3V+G+SOX0iWw5xUlCPX+ERpBbWfwu3uAqn4wYXD3JDE/fVAF668xiV4eTPtlSUd5h0mn+G7uXMMOt kb+20SoEt50f8zw8TrL9t+ZsV11GKZWJpCar5AhXWsn6EEi8I2hLL5vn55ZZmHuGgN4jjmkRl3ToKC LhaXwTBjCJem7N5EH7F75wErEITa55v4Lb4Nfca7vnvtYrI1OA446xa8gHra0SINelTD09/JM/Fw4s WVPBaRZmJK/Tnu79N23No9XBUubmFPv1pNexZsQclicnTpt/BEWhiun7d6lfGB63K1aoHRTR1pcrWv BuALuuz0gqar2zlI0AEQEAAcLAdgQYAQgAIAUCXMbeRQIbDBYhBI4xxYKBgH3ANh5cufaKrc9mtiML AAoJEPaKrc9mtiMLKSEIAIyLCRO2OyZ0IYRvRPpMn4p7E+7Pfcz/0mSkOy+1hshgJnqivXurm8zwGr wdMqeV4eslKR9H1RUdWGUQJNbtwmmjrt5DHpIhYHl5t3FpCBaGbV20Omo00Q38lBl9MtrmZkZw+ktE k6X+0xCKssMF+2MADkSOIufbR5HrDVB89VZOHCO9DeXvCUUAw2hyJiL/LHmLzJ40zYoTmb+F//f0k0 j+tRdbkefyRoCmwG7YGiT+2hnCdgcezswnzah5J3ZKlrg7jOGo1LxtbvNUzxNBbC6S/aNgwm6qxo7x egRhmEl5uZ16zwyj4qz+xkjGy25Of5mWfUDoNw7OT7sjUbHOOMc=";
|
let fixed_header = concat!(
|
||||||
|
"addr=a@b.example.org; prefer-encrypt=mutual; ",
|
||||||
|
"keydata=xsBNBFzG3j0BCAC6iNhT8zydvCXi8LI/gFnkadMbfmSE/rTJskRRra/utGbLyDta/yTrJg",
|
||||||
|
" WL7O3y/g4HdDW/dN2z26Y6W13IMzx9gLInn1KQZChtqWAcr/ReUucXcymwcfg1mdkBGk3TSLeLihN6",
|
||||||
|
" CJx8Wsv8ig+kgAzte4f5rqEEAJVQ9WZHuti7UiYs6oRzqTo06CRe9owVXxzdMf0VDQtf7ZFm9dpzKK",
|
||||||
|
" bhH7Lu8880iiotQ9/yRCkDGp9fNThsrLdZiK6OIAcIBAqi2rI89aS1dAmnRbktQieCx5izzyYkR1Kv",
|
||||||
|
" VL3gTTllHOzfKVEC2asmtWu2e4se/+O4WMIS1eGrn7GeWVb0Vwc5ABEBAAHNETxhQEBiLmV4YW1wbG",
|
||||||
|
" UuZGU+wsCJBBABCAAzAhkBBQJcxt5FAhsDBAsJCAcGFQgJCgsCAxYCARYhBI4xxYKBgH3ANh5cufaK",
|
||||||
|
" rc9mtiMLAAoJEPaKrc9mtiML938H/18F+3Wf9/JaAy/8hCO1v4S2PVBhxaKCokaNFtkfaMRne2l087",
|
||||||
|
" LscCFPiFNyb4mv6Z3YeK8Xpxlp2sI0ecvdiqLUOGfnxS6tQrj+83EjtIrZ/hXOk1h121QFWH9Zg2VN",
|
||||||
|
" HtODXjAgdLDC0NWUrclR0ZOqEDQHeo0ibTILdokVfXFN25wakPmGaYJP2y729cb1ve7RzvIvwn+Ddd",
|
||||||
|
" fxo3ao72rBfLi7l4NQ4S0KsY4cw+/6l5bRCKYCP77wZtvCwUvfVVosLdT43agtSiBI49+ayqvZ8OCv",
|
||||||
|
" SJa61i+v81brTiEy9GBod4eAp45Ibsuemkw+gon4ZOvUXHTjwFB+h63MrozOwE0EXMbePQEIAL/vau",
|
||||||
|
" f1zK8JgCu3V+G+SOX0iWw5xUlCPX+ERpBbWfwu3uAqn4wYXD3JDE/fVAF668xiV4eTPtlSUd5h0mn+",
|
||||||
|
" G7uXMMOtkb+20SoEt50f8zw8TrL9t+ZsV11GKZWJpCar5AhXWsn6EEi8I2hLL5vn55ZZmHuGgN4jjm",
|
||||||
|
" kRl3ToKCLhaXwTBjCJem7N5EH7F75wErEITa55v4Lb4Nfca7vnvtYrI1OA446xa8gHra0SINelTD09",
|
||||||
|
" /JM/Fw4sWVPBaRZmJK/Tnu79N23No9XBUubmFPv1pNexZsQclicnTpt/BEWhiun7d6lfGB63K1aoHR",
|
||||||
|
" TR1pcrWvBuALuuz0gqar2zlI0AEQEAAcLAdgQYAQgAIAUCXMbeRQIbDBYhBI4xxYKBgH3ANh5cufaK",
|
||||||
|
" rc9mtiMLAAoJEPaKrc9mtiMLKSEIAIyLCRO2OyZ0IYRvRPpMn4p7E+7Pfcz/0mSkOy+1hshgJnqivX",
|
||||||
|
" urm8zwGrwdMqeV4eslKR9H1RUdWGUQJNbtwmmjrt5DHpIhYHl5t3FpCBaGbV20Omo00Q38lBl9Mtrm",
|
||||||
|
" ZkZw+ktEk6X+0xCKssMF+2MADkSOIufbR5HrDVB89VZOHCO9DeXvCUUAw2hyJiL/LHmLzJ40zYoTmb",
|
||||||
|
" +F//f0k0j+tRdbkefyRoCmwG7YGiT+2hnCdgcezswnzah5J3ZKlrg7jOGo1LxtbvNUzxNBbC6S/aNg",
|
||||||
|
" wm6qxo7xegRhmEl5uZ16zwyj4qz+xkjGy25Of5mWfUDoNw7OT7sjUbHOOMc="
|
||||||
|
);
|
||||||
|
|
||||||
let ah = Aheader::from_str(fixed_header).expect("failed to parse");
|
let ah = Aheader::from_str(fixed_header).expect("failed to parse");
|
||||||
assert_eq!(ah.addr, "a@b.example.org");
|
assert_eq!(ah.addr, "a@b.example.org");
|
||||||
assert_eq!(ah.prefer_encrypt, EncryptPreference::Mutual);
|
assert_eq!(ah.prefer_encrypt, EncryptPreference::Mutual);
|
||||||
|
assert_eq!(format!("{}", ah), fixed_header);
|
||||||
|
|
||||||
let rendered = ah.to_string();
|
let rendered = ah.to_string();
|
||||||
assert_eq!(rendered, fixed_header);
|
assert_eq!(rendered, fixed_header);
|
||||||
|
|
||||||
let ah = Aheader::from_str(&format!(" _foo; __FOO=BAR ;;; addr = a@b.example.org ;\r\n prefer-encrypt = mutual ; keydata = {}", rawkey())).expect("failed to parse");
|
let ah = Aheader::from_str(&format!(" _foo; __FOO=BAR ;;; addr = a@b.example.org ;\r\n prefer-encrypt = mutual ; keydata = {}", RAWKEY)).expect("failed to parse");
|
||||||
assert_eq!(ah.addr, "a@b.example.org");
|
assert_eq!(ah.addr, "a@b.example.org");
|
||||||
assert_eq!(ah.prefer_encrypt, EncryptPreference::Mutual);
|
assert_eq!(ah.prefer_encrypt, EncryptPreference::Mutual);
|
||||||
|
|
||||||
Aheader::from_str(&format!(
|
Aheader::from_str(&format!(
|
||||||
"addr=a@b.example.org; prefer-encrypt=ignoreUnknownValues; keydata={}",
|
"addr=a@b.example.org; prefer-encrypt=ignoreUnknownValues; keydata={}",
|
||||||
rawkey()
|
RAWKEY
|
||||||
))
|
))
|
||||||
.expect("failed to parse");
|
.expect("failed to parse");
|
||||||
|
|
||||||
Aheader::from_str(&format!("addr=a@b.example.org; keydata={}", rawkey()))
|
Aheader::from_str(&format!("addr=a@b.example.org; keydata={}", RAWKEY))
|
||||||
.expect("failed to parse");
|
.expect("failed to parse");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -266,4 +274,30 @@ mod tests {
|
|||||||
assert!(Aheader::from_str(" ;;").is_err());
|
assert!(Aheader::from_str(" ;;").is_err());
|
||||||
assert!(Aheader::from_str("addr=a@t.de; unknwon=1; keydata=jau").is_err());
|
assert!(Aheader::from_str("addr=a@t.de; unknwon=1; keydata=jau").is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_display_aheader() {
|
||||||
|
assert!(format!(
|
||||||
|
"{}",
|
||||||
|
Aheader::new(
|
||||||
|
"test@example.com".to_string(),
|
||||||
|
SignedPublicKey::from_base64(RAWKEY).unwrap(),
|
||||||
|
EncryptPreference::Mutual
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.contains("prefer-encrypt=mutual;"));
|
||||||
|
|
||||||
|
// According to Autocrypt Level 1 specification,
|
||||||
|
// only "prefer-encrypt=mutual;" can be used.
|
||||||
|
// If the setting is nopreference, the whole attribute is omitted.
|
||||||
|
assert!(!format!(
|
||||||
|
"{}",
|
||||||
|
Aheader::new(
|
||||||
|
"test@example.com".to_string(),
|
||||||
|
SignedPublicKey::from_base64(RAWKEY).unwrap(),
|
||||||
|
EncryptPreference::NoPreference
|
||||||
|
)
|
||||||
|
)
|
||||||
|
.contains("prefer-encrypt"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
699
src/blob.rs
Normal file
@@ -0,0 +1,699 @@
|
|||||||
|
//! # Blob directory management
|
||||||
|
|
||||||
|
use std::ffi::OsStr;
|
||||||
|
use std::fmt;
|
||||||
|
|
||||||
|
use async_std::path::{Path, PathBuf};
|
||||||
|
use async_std::prelude::*;
|
||||||
|
use async_std::{fs, io};
|
||||||
|
|
||||||
|
use image::GenericImageView;
|
||||||
|
use num_traits::FromPrimitive;
|
||||||
|
use thiserror::Error;
|
||||||
|
|
||||||
|
use crate::config::Config;
|
||||||
|
use crate::constants::*;
|
||||||
|
use crate::context::Context;
|
||||||
|
use crate::error::Error;
|
||||||
|
use crate::events::Event;
|
||||||
|
use crate::message;
|
||||||
|
|
||||||
|
/// Represents a file in the blob directory.
|
||||||
|
///
|
||||||
|
/// The object has a name, which will always be valid UTF-8. Having a
|
||||||
|
/// blob object does not imply the respective file exists, however
|
||||||
|
/// when using one of the `create*()` methods a unique file is
|
||||||
|
/// created.
|
||||||
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
pub struct BlobObject<'a> {
|
||||||
|
blobdir: &'a Path,
|
||||||
|
name: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> BlobObject<'a> {
|
||||||
|
/// Creates a new blob object with a unique name.
|
||||||
|
///
|
||||||
|
/// Creates a new file in the blob directory. The name will be
|
||||||
|
/// derived from the platform-agnostic basename of the suggested
|
||||||
|
/// name, followed by a random number and followed by a possible
|
||||||
|
/// extension. The `data` will be written into the file without
|
||||||
|
/// race-conditions.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// [BlobError::CreateFailure] is used when the file could not
|
||||||
|
/// be created. You can expect [BlobError.cause] to contain an
|
||||||
|
/// underlying error.
|
||||||
|
///
|
||||||
|
/// [BlobError::WriteFailure] is used when the file could not
|
||||||
|
/// be written to. You can expect [BlobError.cause] to contain an
|
||||||
|
/// underlying error.
|
||||||
|
pub async fn create(
|
||||||
|
context: &'a Context,
|
||||||
|
suggested_name: impl AsRef<str>,
|
||||||
|
data: &[u8],
|
||||||
|
) -> std::result::Result<BlobObject<'a>, BlobError> {
|
||||||
|
let blobdir = context.get_blobdir();
|
||||||
|
let (stem, ext) = BlobObject::sanitise_name(suggested_name.as_ref());
|
||||||
|
let (name, mut file) = BlobObject::create_new_file(&blobdir, &stem, &ext).await?;
|
||||||
|
file.write_all(data)
|
||||||
|
.await
|
||||||
|
.map_err(|err| BlobError::WriteFailure {
|
||||||
|
blobdir: blobdir.to_path_buf(),
|
||||||
|
blobname: name.clone(),
|
||||||
|
cause: err.into(),
|
||||||
|
})?;
|
||||||
|
let blob = BlobObject {
|
||||||
|
blobdir,
|
||||||
|
name: format!("$BLOBDIR/{}", name),
|
||||||
|
};
|
||||||
|
context.emit_event(Event::NewBlobFile(blob.as_name().to_string()));
|
||||||
|
Ok(blob)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Creates a new file, returning a tuple of the name and the handle.
|
||||||
|
async fn create_new_file(
|
||||||
|
dir: &Path,
|
||||||
|
stem: &str,
|
||||||
|
ext: &str,
|
||||||
|
) -> Result<(String, fs::File), BlobError> {
|
||||||
|
let max_attempt = 15;
|
||||||
|
let mut name = format!("{}{}", stem, ext);
|
||||||
|
for attempt in 0..max_attempt {
|
||||||
|
let path = dir.join(&name);
|
||||||
|
match fs::OpenOptions::new()
|
||||||
|
.create_new(true)
|
||||||
|
.write(true)
|
||||||
|
.open(&path)
|
||||||
|
.await
|
||||||
|
{
|
||||||
|
Ok(file) => return Ok((name, file)),
|
||||||
|
Err(err) => {
|
||||||
|
if attempt == max_attempt {
|
||||||
|
return Err(BlobError::CreateFailure {
|
||||||
|
blobdir: dir.to_path_buf(),
|
||||||
|
blobname: name,
|
||||||
|
cause: err,
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
name = format!("{}-{}{}", stem, rand::random::<u32>(), ext);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// This is supposed to be unreachable, but the compiler doesn't know.
|
||||||
|
Err(BlobError::CreateFailure {
|
||||||
|
blobdir: dir.to_path_buf(),
|
||||||
|
blobname: name,
|
||||||
|
cause: std::io::Error::new(std::io::ErrorKind::Other, "supposedly unreachable"),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a new blob object with unique name by copying an existing file.
|
||||||
|
///
|
||||||
|
/// This creates a new blob as described in [BlobObject::create]
|
||||||
|
/// but also copies an existing file into it. This is done in a
|
||||||
|
/// in way which avoids race-conditions when multiple files are
|
||||||
|
/// concurrently created.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// In addition to the errors in [BlobObject::create] the
|
||||||
|
/// [BlobError::CopyFailure] is used when the data can not be
|
||||||
|
/// copied.
|
||||||
|
pub async fn create_and_copy(
|
||||||
|
context: &'a Context,
|
||||||
|
src: impl AsRef<Path>,
|
||||||
|
) -> std::result::Result<BlobObject<'a>, BlobError> {
|
||||||
|
let mut src_file =
|
||||||
|
fs::File::open(src.as_ref())
|
||||||
|
.await
|
||||||
|
.map_err(|err| BlobError::CopyFailure {
|
||||||
|
blobdir: context.get_blobdir().to_path_buf(),
|
||||||
|
blobname: String::from(""),
|
||||||
|
src: src.as_ref().to_path_buf(),
|
||||||
|
cause: err,
|
||||||
|
})?;
|
||||||
|
let (stem, ext) = BlobObject::sanitise_name(&src.as_ref().to_string_lossy());
|
||||||
|
let (name, mut dst_file) =
|
||||||
|
BlobObject::create_new_file(context.get_blobdir(), &stem, &ext).await?;
|
||||||
|
let name_for_err = name.clone();
|
||||||
|
if let Err(err) = io::copy(&mut src_file, &mut dst_file).await {
|
||||||
|
{
|
||||||
|
// Attempt to remove the failed file, swallow errors resulting from that.
|
||||||
|
let path = context.get_blobdir().join(&name_for_err);
|
||||||
|
fs::remove_file(path).await.ok();
|
||||||
|
}
|
||||||
|
return Err(BlobError::CopyFailure {
|
||||||
|
blobdir: context.get_blobdir().to_path_buf(),
|
||||||
|
blobname: name_for_err,
|
||||||
|
src: src.as_ref().to_path_buf(),
|
||||||
|
cause: err,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let blob = BlobObject {
|
||||||
|
blobdir: context.get_blobdir(),
|
||||||
|
name: format!("$BLOBDIR/{}", name),
|
||||||
|
};
|
||||||
|
context.emit_event(Event::NewBlobFile(blob.as_name().to_string()));
|
||||||
|
Ok(blob)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Creates a blob from a file, possibly copying it to the blobdir.
|
||||||
|
///
|
||||||
|
/// If the source file is not a path to into the blob directory
|
||||||
|
/// the file will be copied into the blob directory first. If the
|
||||||
|
/// source file is already in the blobdir it will not be copied
|
||||||
|
/// and only be created if it is a valid blobname, that is no
|
||||||
|
/// subdirectory is used and [BlobObject::sanitise_name] does not
|
||||||
|
/// modify the filename.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// This merely delegates to the [BlobObject::create_and_copy] and
|
||||||
|
/// the [BlobObject::from_path] methods. See those for possible
|
||||||
|
/// errors.
|
||||||
|
pub async fn new_from_path(
|
||||||
|
context: &Context,
|
||||||
|
src: impl AsRef<Path>,
|
||||||
|
) -> std::result::Result<BlobObject<'_>, BlobError> {
|
||||||
|
if src.as_ref().starts_with(context.get_blobdir()) {
|
||||||
|
BlobObject::from_path(context, src)
|
||||||
|
} else {
|
||||||
|
BlobObject::create_and_copy(context, src).await
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a [BlobObject] for an existing blob from a path.
|
||||||
|
///
|
||||||
|
/// The path must designate a file directly in the blobdir and
|
||||||
|
/// must use a valid blob name. That is after sanitisation the
|
||||||
|
/// name must still be the same, that means it must be valid UTF-8
|
||||||
|
/// and not have any special characters in it.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// [BlobError::WrongBlobdir] is used if the path is not in
|
||||||
|
/// the blob directory.
|
||||||
|
///
|
||||||
|
/// [BlobError::WrongName] is used if the file name does not
|
||||||
|
/// remain identical after sanitisation.
|
||||||
|
pub fn from_path(
|
||||||
|
context: &Context,
|
||||||
|
path: impl AsRef<Path>,
|
||||||
|
) -> std::result::Result<BlobObject, BlobError> {
|
||||||
|
let rel_path = path
|
||||||
|
.as_ref()
|
||||||
|
.strip_prefix(context.get_blobdir())
|
||||||
|
.map_err(|_| BlobError::WrongBlobdir {
|
||||||
|
blobdir: context.get_blobdir().to_path_buf(),
|
||||||
|
src: path.as_ref().to_path_buf(),
|
||||||
|
})?;
|
||||||
|
if !BlobObject::is_acceptible_blob_name(&rel_path) {
|
||||||
|
return Err(BlobError::WrongName {
|
||||||
|
blobname: path.as_ref().to_path_buf(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
let name = rel_path.to_str().ok_or_else(|| BlobError::WrongName {
|
||||||
|
blobname: path.as_ref().to_path_buf(),
|
||||||
|
})?;
|
||||||
|
BlobObject::from_name(context, name.to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns a [BlobObject] for an existing blob.
|
||||||
|
///
|
||||||
|
/// The `name` may optionally be prefixed with the `$BLOBDIR/`
|
||||||
|
/// prefixed, as returned by [BlobObject::as_name]. This is how
|
||||||
|
/// you want to create a [BlobObject] for a filename read from the
|
||||||
|
/// database.
|
||||||
|
///
|
||||||
|
/// # Errors
|
||||||
|
///
|
||||||
|
/// [BlobError::WrongName] is used if the name is not a valid
|
||||||
|
/// blobname, i.e. if [BlobObject::sanitise_name] does modify the
|
||||||
|
/// provided name.
|
||||||
|
pub fn from_name(
|
||||||
|
context: &'a Context,
|
||||||
|
name: String,
|
||||||
|
) -> std::result::Result<BlobObject<'a>, BlobError> {
|
||||||
|
let name: String = match name.starts_with("$BLOBDIR/") {
|
||||||
|
true => name.splitn(2, '/').last().unwrap().to_string(),
|
||||||
|
false => name,
|
||||||
|
};
|
||||||
|
if !BlobObject::is_acceptible_blob_name(&name) {
|
||||||
|
return Err(BlobError::WrongName {
|
||||||
|
blobname: PathBuf::from(name),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
Ok(BlobObject {
|
||||||
|
blobdir: context.get_blobdir(),
|
||||||
|
name: format!("$BLOBDIR/{}", name),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the absolute path to the blob in the filesystem.
|
||||||
|
pub fn to_abs_path(&self) -> PathBuf {
|
||||||
|
let fname = Path::new(&self.name).strip_prefix("$BLOBDIR/").unwrap();
|
||||||
|
self.blobdir.join(fname)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the blob name, as stored in the database.
|
||||||
|
///
|
||||||
|
/// This returns the blob in the `$BLOBDIR/<name>` format used in
|
||||||
|
/// the database. Do not use this unless you're about to store
|
||||||
|
/// this string in the database or [Params]. Eventually even
|
||||||
|
/// those conversions should be handled by the type system.
|
||||||
|
///
|
||||||
|
/// [Params]: crate::param::Params
|
||||||
|
pub fn as_name(&self) -> &str {
|
||||||
|
&self.name
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the filename of the blob.
|
||||||
|
pub fn as_file_name(&self) -> &str {
|
||||||
|
self.name.rsplitn(2, '/').next().unwrap()
|
||||||
|
}
|
||||||
|
|
||||||
|
/// The path relative in the blob directory.
|
||||||
|
pub fn as_rel_path(&self) -> &Path {
|
||||||
|
Path::new(self.as_file_name())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Returns the extension of the blob.
|
||||||
|
///
|
||||||
|
/// If a blob's filename has an extension, it is always guaranteed
|
||||||
|
/// to be lowercase.
|
||||||
|
pub fn suffix(&self) -> Option<&str> {
|
||||||
|
let ext = self.name.rsplitn(2, '.').next();
|
||||||
|
if ext == Some(&self.name) {
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
ext
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Create a safe name based on a messy input string.
|
||||||
|
///
|
||||||
|
/// The safe name will be a valid filename on Unix and Windows and
|
||||||
|
/// not contain any path separators. The input can contain path
|
||||||
|
/// segments separated by either Unix or Windows path separators,
|
||||||
|
/// the rightmost non-empty segment will be used as name,
|
||||||
|
/// sanitised for special characters.
|
||||||
|
///
|
||||||
|
/// The resulting name is returned as a tuple, the first part
|
||||||
|
/// being the stem or basename and the second being an extension,
|
||||||
|
/// including the dot. E.g. "foo.txt" is returned as `("foo",
|
||||||
|
/// ".txt")` while "bar" is returned as `("bar", "")`.
|
||||||
|
///
|
||||||
|
/// The extension part will always be lowercased.
|
||||||
|
fn sanitise_name(name: &str) -> (String, String) {
|
||||||
|
let mut name = name.to_string();
|
||||||
|
for part in name.rsplit('/') {
|
||||||
|
if !part.is_empty() {
|
||||||
|
name = part.to_string();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for part in name.rsplit('\\') {
|
||||||
|
if !part.is_empty() {
|
||||||
|
name = part.to_string();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let opts = sanitize_filename::Options {
|
||||||
|
truncate: true,
|
||||||
|
windows: true,
|
||||||
|
replacement: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
let clean = sanitize_filename::sanitize_with_options(name, opts);
|
||||||
|
let mut iter = clean.splitn(2, '.');
|
||||||
|
let stem: String = iter.next().unwrap_or_default().chars().take(64).collect();
|
||||||
|
let ext: String = iter.next().unwrap_or_default().chars().take(32).collect();
|
||||||
|
if ext.is_empty() {
|
||||||
|
(stem, "".to_string())
|
||||||
|
} else {
|
||||||
|
(stem, format!(".{}", ext).to_lowercase())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Checks whether a name is a valid blob name.
|
||||||
|
///
|
||||||
|
/// This is slightly less strict than stanitise_name, presumably
|
||||||
|
/// someone already created a file with such a name so we just
|
||||||
|
/// ensure it's not actually a path in disguise is actually utf-8.
|
||||||
|
fn is_acceptible_blob_name(name: impl AsRef<OsStr>) -> bool {
|
||||||
|
let uname = match name.as_ref().to_str() {
|
||||||
|
Some(name) => name,
|
||||||
|
None => return false,
|
||||||
|
};
|
||||||
|
if uname.find('/').is_some() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if uname.find('\\').is_some() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if uname.find('\0').is_some() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn recode_to_avatar_size(&self, context: &Context) -> Result<(), BlobError> {
|
||||||
|
let blob_abs = self.to_abs_path();
|
||||||
|
let img = image::open(&blob_abs).map_err(|err| BlobError::RecodeFailure {
|
||||||
|
blobdir: context.get_blobdir().to_path_buf(),
|
||||||
|
blobname: blob_abs.to_str().unwrap_or_default().to_string(),
|
||||||
|
cause: err,
|
||||||
|
})?;
|
||||||
|
|
||||||
|
if img.width() <= AVATAR_SIZE && img.height() <= AVATAR_SIZE {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let img = img.thumbnail(AVATAR_SIZE, AVATAR_SIZE);
|
||||||
|
|
||||||
|
img.save(&blob_abs).map_err(|err| BlobError::WriteFailure {
|
||||||
|
blobdir: context.get_blobdir().to_path_buf(),
|
||||||
|
blobname: blob_abs.to_str().unwrap_or_default().to_string(),
|
||||||
|
cause: err.into(),
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn recode_to_image_size(&self, context: &Context) -> Result<(), BlobError> {
|
||||||
|
let blob_abs = self.to_abs_path();
|
||||||
|
if message::guess_msgtype_from_suffix(Path::new(&blob_abs))
|
||||||
|
!= Some((Viewtype::Image, "image/jpeg"))
|
||||||
|
{
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let img = image::open(&blob_abs).map_err(|err| BlobError::RecodeFailure {
|
||||||
|
blobdir: context.get_blobdir().to_path_buf(),
|
||||||
|
blobname: blob_abs.to_str().unwrap_or_default().to_string(),
|
||||||
|
cause: err,
|
||||||
|
})?;
|
||||||
|
|
||||||
|
let img_wh = if MediaQuality::from_i32(context.get_config_int(Config::MediaQuality).await)
|
||||||
|
.unwrap_or_default()
|
||||||
|
== MediaQuality::Balanced
|
||||||
|
{
|
||||||
|
BALANCED_IMAGE_SIZE
|
||||||
|
} else {
|
||||||
|
WORSE_IMAGE_SIZE
|
||||||
|
};
|
||||||
|
|
||||||
|
if img.width() <= img_wh && img.height() <= img_wh {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let mut img = img.thumbnail(img_wh, img_wh);
|
||||||
|
match self.get_exif_orientation(context) {
|
||||||
|
Ok(90) => img = img.rotate90(),
|
||||||
|
Ok(180) => img = img.rotate180(),
|
||||||
|
Ok(270) => img = img.rotate270(),
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
|
||||||
|
img.save(&blob_abs).map_err(|err| BlobError::WriteFailure {
|
||||||
|
blobdir: context.get_blobdir().to_path_buf(),
|
||||||
|
blobname: blob_abs.to_str().unwrap_or_default().to_string(),
|
||||||
|
cause: err.into(),
|
||||||
|
})?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_exif_orientation(&self, context: &Context) -> Result<i32, Error> {
|
||||||
|
let file = std::fs::File::open(self.to_abs_path())?;
|
||||||
|
let mut bufreader = std::io::BufReader::new(&file);
|
||||||
|
let exifreader = exif::Reader::new();
|
||||||
|
let exif = exifreader.read_from_container(&mut bufreader)?;
|
||||||
|
if let Some(orientation) = exif.get_field(exif::Tag::Orientation, exif::In::PRIMARY) {
|
||||||
|
// possible orientation values are described at http://sylvana.net/jpegcrop/exif_orientation.html
|
||||||
|
// we only use rotation, in practise, flipping is not used.
|
||||||
|
match orientation.value.get_uint(0) {
|
||||||
|
Some(3) => return Ok(180),
|
||||||
|
Some(6) => return Ok(90),
|
||||||
|
Some(8) => return Ok(270),
|
||||||
|
other => warn!(context, "exif orientation value ignored: {:?}", other),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<'a> fmt::Display for BlobObject<'a> {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
write!(f, "$BLOBDIR/{}", self.name)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Errors for the [BlobObject].
|
||||||
|
#[derive(Debug, Error)]
|
||||||
|
pub enum BlobError {
|
||||||
|
#[error("Failed to create blob {blobname} in {}", .blobdir.display())]
|
||||||
|
CreateFailure {
|
||||||
|
blobdir: PathBuf,
|
||||||
|
blobname: String,
|
||||||
|
#[source]
|
||||||
|
cause: std::io::Error,
|
||||||
|
},
|
||||||
|
#[error("Failed to write data to blob {blobname} in {}", .blobdir.display())]
|
||||||
|
WriteFailure {
|
||||||
|
blobdir: PathBuf,
|
||||||
|
blobname: String,
|
||||||
|
#[source]
|
||||||
|
cause: anyhow::Error,
|
||||||
|
},
|
||||||
|
#[error("Failed to copy data from {} to blob {blobname} in {}", .src.display(), .blobdir.display())]
|
||||||
|
CopyFailure {
|
||||||
|
blobdir: PathBuf,
|
||||||
|
blobname: String,
|
||||||
|
src: PathBuf,
|
||||||
|
#[source]
|
||||||
|
cause: std::io::Error,
|
||||||
|
},
|
||||||
|
#[error("Failed to recode to blob {blobname} in {}", .blobdir.display())]
|
||||||
|
RecodeFailure {
|
||||||
|
blobdir: PathBuf,
|
||||||
|
blobname: String,
|
||||||
|
#[source]
|
||||||
|
cause: image::ImageError,
|
||||||
|
},
|
||||||
|
#[error("File path {} is not in {}", .src.display(), .blobdir.display())]
|
||||||
|
WrongBlobdir { blobdir: PathBuf, src: PathBuf },
|
||||||
|
#[error("Blob has a badname {}", .blobname.display())]
|
||||||
|
WrongName { blobname: PathBuf },
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
use crate::test_utils::*;
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn test_create() {
|
||||||
|
let t = TestContext::new().await;
|
||||||
|
let blob = BlobObject::create(&t.ctx, "foo", b"hello").await.unwrap();
|
||||||
|
let fname = t.ctx.get_blobdir().join("foo");
|
||||||
|
let data = fs::read(fname).await.unwrap();
|
||||||
|
assert_eq!(data, b"hello");
|
||||||
|
assert_eq!(blob.as_name(), "$BLOBDIR/foo");
|
||||||
|
assert_eq!(blob.to_abs_path(), t.ctx.get_blobdir().join("foo"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn test_lowercase_ext() {
|
||||||
|
let t = TestContext::new().await;
|
||||||
|
let blob = BlobObject::create(&t.ctx, "foo.TXT", b"hello")
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(blob.as_name(), "$BLOBDIR/foo.txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn test_as_file_name() {
|
||||||
|
let t = TestContext::new().await;
|
||||||
|
let blob = BlobObject::create(&t.ctx, "foo.txt", b"hello")
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(blob.as_file_name(), "foo.txt");
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn test_as_rel_path() {
|
||||||
|
let t = TestContext::new().await;
|
||||||
|
let blob = BlobObject::create(&t.ctx, "foo.txt", b"hello")
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(blob.as_rel_path(), Path::new("foo.txt"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn test_suffix() {
|
||||||
|
let t = TestContext::new().await;
|
||||||
|
let blob = BlobObject::create(&t.ctx, "foo.txt", b"hello")
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
assert_eq!(blob.suffix(), Some("txt"));
|
||||||
|
let blob = BlobObject::create(&t.ctx, "bar", b"world").await.unwrap();
|
||||||
|
assert_eq!(blob.suffix(), None);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn test_create_dup() {
|
||||||
|
let t = TestContext::new().await;
|
||||||
|
BlobObject::create(&t.ctx, "foo.txt", b"hello")
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let foo_path = t.ctx.get_blobdir().join("foo.txt");
|
||||||
|
assert!(foo_path.exists().await);
|
||||||
|
BlobObject::create(&t.ctx, "foo.txt", b"world")
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let mut dir = fs::read_dir(t.ctx.get_blobdir()).await.unwrap();
|
||||||
|
while let Some(dirent) = dir.next().await {
|
||||||
|
let fname = dirent.unwrap().file_name();
|
||||||
|
if fname == foo_path.file_name().unwrap() {
|
||||||
|
assert_eq!(fs::read(&foo_path).await.unwrap(), b"hello");
|
||||||
|
} else {
|
||||||
|
let name = fname.to_str().unwrap();
|
||||||
|
assert!(name.starts_with("foo"));
|
||||||
|
assert!(name.ends_with(".txt"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn test_double_ext_preserved() {
|
||||||
|
let t = TestContext::new().await;
|
||||||
|
BlobObject::create(&t.ctx, "foo.tar.gz", b"hello")
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let foo_path = t.ctx.get_blobdir().join("foo.tar.gz");
|
||||||
|
assert!(foo_path.exists().await);
|
||||||
|
BlobObject::create(&t.ctx, "foo.tar.gz", b"world")
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let mut dir = fs::read_dir(t.ctx.get_blobdir()).await.unwrap();
|
||||||
|
while let Some(dirent) = dir.next().await {
|
||||||
|
let fname = dirent.unwrap().file_name();
|
||||||
|
if fname == foo_path.file_name().unwrap() {
|
||||||
|
assert_eq!(fs::read(&foo_path).await.unwrap(), b"hello");
|
||||||
|
} else {
|
||||||
|
let name = fname.to_str().unwrap();
|
||||||
|
println!("{}", name);
|
||||||
|
assert!(name.starts_with("foo"));
|
||||||
|
assert!(name.ends_with(".tar.gz"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn test_create_long_names() {
|
||||||
|
let t = TestContext::new().await;
|
||||||
|
let s = "1".repeat(150);
|
||||||
|
let blob = BlobObject::create(&t.ctx, &s, b"data").await.unwrap();
|
||||||
|
let blobname = blob.as_name().split('/').last().unwrap();
|
||||||
|
assert!(blobname.len() < 128);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn test_create_and_copy() {
|
||||||
|
let t = TestContext::new().await;
|
||||||
|
let src = t.dir.path().join("src");
|
||||||
|
fs::write(&src, b"boo").await.unwrap();
|
||||||
|
let blob = BlobObject::create_and_copy(&t.ctx, &src).await.unwrap();
|
||||||
|
assert_eq!(blob.as_name(), "$BLOBDIR/src");
|
||||||
|
let data = fs::read(blob.to_abs_path()).await.unwrap();
|
||||||
|
assert_eq!(data, b"boo");
|
||||||
|
|
||||||
|
let whoops = t.dir.path().join("whoops");
|
||||||
|
assert!(BlobObject::create_and_copy(&t.ctx, &whoops).await.is_err());
|
||||||
|
let whoops = t.ctx.get_blobdir().join("whoops");
|
||||||
|
assert!(!whoops.exists().await);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[async_std::test]
|
||||||
|
async fn test_create_from_path() {
|
||||||
|
let t = TestContext::new().await;
|
||||||
|
|
||||||
|
let src_ext = t.dir.path().join("external");
|
||||||
|
fs::write(&src_ext, b"boo").await.unwrap();
|
||||||
|
let blob = BlobObject::new_from_path(&t.ctx, &src_ext).await.unwrap();
|
||||||
|
assert_eq!(blob.as_name(), "$BLOBDIR/external");
|
||||||
|
let data = fs::read(blob.to_abs_path()).await.unwrap();
|
||||||
|
assert_eq!(data, b"boo");
|
||||||
|
|
||||||
|
let src_int = t.ctx.get_blobdir().join("internal");
|
||||||
|
fs::write(&src_int, b"boo").await.unwrap();
|
||||||
|
let blob = BlobObject::new_from_path(&t.ctx, &src_int).await.unwrap();
|
||||||
|
assert_eq!(blob.as_name(), "$BLOBDIR/internal");
|
||||||
|
let data = fs::read(blob.to_abs_path()).await.unwrap();
|
||||||
|
assert_eq!(data, b"boo");
|
||||||
|
}
|
||||||
|
#[async_std::test]
|
||||||
|
async fn test_create_from_name_long() {
|
||||||
|
let t = TestContext::new().await;
|
||||||
|
let src_ext = t.dir.path().join("autocrypt-setup-message-4137848473.html");
|
||||||
|
fs::write(&src_ext, b"boo").await.unwrap();
|
||||||
|
let blob = BlobObject::new_from_path(&t.ctx, &src_ext).await.unwrap();
|
||||||
|
assert_eq!(
|
||||||
|
blob.as_name(),
|
||||||
|
"$BLOBDIR/autocrypt-setup-message-4137848473.html"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_is_blob_name() {
|
||||||
|
assert!(BlobObject::is_acceptible_blob_name("foo"));
|
||||||
|
assert!(BlobObject::is_acceptible_blob_name("foo.txt"));
|
||||||
|
assert!(BlobObject::is_acceptible_blob_name("f".repeat(128)));
|
||||||
|
assert!(!BlobObject::is_acceptible_blob_name("foo/bar"));
|
||||||
|
assert!(!BlobObject::is_acceptible_blob_name("foo\\bar"));
|
||||||
|
assert!(!BlobObject::is_acceptible_blob_name("foo\x00bar"));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_sanitise_name() {
|
||||||
|
let (stem, ext) =
|
||||||
|
BlobObject::sanitise_name("Я ЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯЯ.txt");
|
||||||
|
assert_eq!(ext, ".txt");
|
||||||
|
assert!(!stem.is_empty());
|
||||||
|
|
||||||
|
// the extensions are kept together as between stem and extension a number may be added -
|
||||||
|
// and `foo.tar.gz` should become `foo-1234.tar.gz` and not `foo.tar-1234.gz`
|
||||||
|
let (stem, ext) = BlobObject::sanitise_name("wot.tar.gz");
|
||||||
|
assert_eq!(stem, "wot");
|
||||||
|
assert_eq!(ext, ".tar.gz");
|
||||||
|
|
||||||
|
let (stem, ext) = BlobObject::sanitise_name(".foo.bar");
|
||||||
|
assert_eq!(stem, "");
|
||||||
|
assert_eq!(ext, ".foo.bar");
|
||||||
|
|
||||||
|
let (stem, ext) = BlobObject::sanitise_name("foo?.bar");
|
||||||
|
assert!(stem.contains("foo"));
|
||||||
|
assert!(!stem.contains("?"));
|
||||||
|
assert_eq!(ext, ".bar");
|
||||||
|
|
||||||
|
let (stem, ext) = BlobObject::sanitise_name("no-extension");
|
||||||
|
assert_eq!(stem, "no-extension");
|
||||||
|
assert_eq!(ext, "");
|
||||||
|
|
||||||
|
let (stem, ext) = BlobObject::sanitise_name("path/ignored\\this: is* forbidden?.c");
|
||||||
|
assert_eq!(ext, ".c");
|
||||||
|
assert!(!stem.contains("path"));
|
||||||
|
assert!(!stem.contains("ignored"));
|
||||||
|
assert!(stem.contains("this"));
|
||||||
|
assert!(stem.contains("forbidden"));
|
||||||
|
assert!(!stem.contains("/"));
|
||||||
|
assert!(!stem.contains("\\"));
|
||||||
|
assert!(!stem.contains(":"));
|
||||||
|
assert!(!stem.contains("*"));
|
||||||
|
assert!(!stem.contains("?"));
|
||||||
|
}
|
||||||
|
}
|
||||||