@@ -26,7 +26,7 @@ use crate::debug_logging::DebugLogging;
26
26
use crate :: download:: DownloadState ;
27
27
use crate :: events:: { Event , EventEmitter , EventType , Events } ;
28
28
use crate :: imap:: { FolderMeaning , Imap , ServerMetadata } ;
29
- use crate :: key:: { load_self_public_key, load_self_secret_key, DcKey as _} ;
29
+ use crate :: key:: { load_self_public_key, load_self_secret_key, self_fingerprint , DcKey as _} ;
30
30
use crate :: log:: LogExt ;
31
31
use crate :: log:: { info, warn} ;
32
32
use crate :: login_param:: { ConfiguredLoginParam , EnteredLoginParam } ;
@@ -1062,197 +1062,6 @@ impl Context {
1062
1062
Ok ( res)
1063
1063
}
1064
1064
1065
- async fn get_self_report ( & self ) -> Result < String > {
1066
- #[ derive( Serialize ) ]
1067
- struct Statistics {
1068
- core_version : String ,
1069
- num_msgs : u32 ,
1070
- num_chats : u32 ,
1071
- db_size : u64 ,
1072
- key_created : i64 ,
1073
- chat_numbers : ChatNumbers ,
1074
- self_reporting_id : String ,
1075
- }
1076
- #[ derive( Default , Serialize ) ]
1077
- struct ChatNumbers {
1078
- protected : u32 ,
1079
- protection_broken : u32 ,
1080
- opportunistic_dc : u32 ,
1081
- opportunistic_mua : u32 ,
1082
- unencrypted_dc : u32 ,
1083
- unencrypted_mua : u32 ,
1084
- }
1085
-
1086
- let num_msgs: u32 = self
1087
- . sql
1088
- . query_get_value (
1089
- "SELECT COUNT(*) FROM msgs WHERE hidden=0 AND chat_id!=?" ,
1090
- ( DC_CHAT_ID_TRASH , ) ,
1091
- )
1092
- . await ?
1093
- . unwrap_or_default ( ) ;
1094
-
1095
- let num_chats: u32 = self
1096
- . sql
1097
- . query_get_value ( "SELECT COUNT(*) FROM chats WHERE id>9 AND blocked!=1" , ( ) )
1098
- . await ?
1099
- . unwrap_or_default ( ) ;
1100
-
1101
- let db_size = tokio:: fs:: metadata ( & self . sql . dbfile ) . await ?. len ( ) ;
1102
-
1103
- let key_created = load_self_secret_key ( self )
1104
- . await ?
1105
- . primary_key
1106
- . created_at ( )
1107
- . timestamp ( ) ;
1108
-
1109
- // how many of the chats active in the last months are:
1110
- // - protected
1111
- // - protection-broken
1112
- // - opportunistic-encrypted and the contact uses Delta Chat
1113
- // - opportunistic-encrypted and the contact uses a classical MUA
1114
- // - unencrypted and the contact uses Delta Chat
1115
- // - unencrypted and the contact uses a classical MUA
1116
- let three_months_ago = time ( ) . saturating_sub ( 3600 * 24 * 30 * 3 ) ;
1117
- let chat_numbers = self
1118
- . sql
1119
- . query_map (
1120
- "SELECT c.protected, m.param, m.msgrmsg
1121
- FROM chats c
1122
- JOIN msgs m
1123
- ON c.id=m.chat_id
1124
- AND m.id=(
1125
- SELECT id
1126
- FROM msgs
1127
- WHERE chat_id=c.id
1128
- AND hidden=0
1129
- AND download_state=?
1130
- AND to_id!=?
1131
- ORDER BY timestamp DESC, id DESC LIMIT 1)
1132
- WHERE c.id>9
1133
- AND (c.blocked=0 OR c.blocked=2)
1134
- AND IFNULL(m.timestamp,c.created_timestamp) > ?
1135
- GROUP BY c.id" ,
1136
- ( DownloadState :: Done , ContactId :: INFO , three_months_ago) ,
1137
- |row| {
1138
- let protected: ProtectionStatus = row. get ( 0 ) ?;
1139
- let message_param: Params =
1140
- row. get :: < _ , String > ( 1 ) ?. parse ( ) . unwrap_or_default ( ) ;
1141
- let is_dc_message: bool = row. get ( 2 ) ?;
1142
- Ok ( ( protected, message_param, is_dc_message) )
1143
- } ,
1144
- |rows| {
1145
- let mut chats = ChatNumbers :: default ( ) ;
1146
- for row in rows {
1147
- let ( protected, message_param, is_dc_message) = row?;
1148
- let encrypted = message_param
1149
- . get_bool ( Param :: GuaranteeE2ee )
1150
- . unwrap_or ( false ) ;
1151
-
1152
- if protected == ProtectionStatus :: Protected {
1153
- chats. protected += 1 ;
1154
- } else if protected == ProtectionStatus :: ProtectionBroken {
1155
- chats. protection_broken += 1 ;
1156
- } else if encrypted {
1157
- if is_dc_message {
1158
- chats. opportunistic_dc += 1 ;
1159
- } else {
1160
- chats. opportunistic_mua += 1 ;
1161
- }
1162
- } else if is_dc_message {
1163
- chats. unencrypted_dc += 1 ;
1164
- } else {
1165
- chats. unencrypted_mua += 1 ;
1166
- }
1167
- }
1168
- Ok ( chats)
1169
- } ,
1170
- )
1171
- . await ?;
1172
-
1173
- let self_reporting_id = match self . get_config ( Config :: SelfReportingId ) . await ? {
1174
- Some ( id) => id,
1175
- None => {
1176
- let id = create_id ( ) ;
1177
- self . set_config_internal ( Config :: SelfReportingId , Some ( & id) )
1178
- . await ?;
1179
- id
1180
- }
1181
- } ;
1182
- let statistics = Statistics {
1183
- core_version : get_version_str ( ) . to_string ( ) ,
1184
- num_msgs,
1185
- num_chats,
1186
- db_size,
1187
- key_created,
1188
- chat_numbers,
1189
- self_reporting_id,
1190
- } ;
1191
-
1192
- Ok ( serde_json:: to_string_pretty ( & statistics) ?)
1193
- }
1194
-
1195
- /// Drafts a message with statistics about the usage of Delta Chat.
1196
- /// The user can inspect the message if they want, and then hit "Send".
1197
- ///
1198
- /// On the other end, a bot will receive the message and make it available
1199
- /// to Delta Chat's developers.
1200
- pub async fn send_self_report ( & self ) -> Result < ChatId > {
1201
- info ! ( self , "Sending self report." ) ;
1202
- // Setting `Config::LastHousekeeping` at the beginning avoids endless loops when things do not
1203
- // work out for whatever reason or are interrupted by the OS.
1204
- self . set_config_internal ( Config :: LastSelfReportSent , Some ( & time ( ) . to_string ( ) ) )
1205
- . await
1206
- . log_err ( self )
1207
- . ok ( ) ;
1208
-
1209
- const SELF_REPORTING_BOT_VCARD : & str = include_str ! ( "../assets/self-reporting-bot.vcf" ) ;
1210
- let contact_id: ContactId = * import_vcard ( self , SELF_REPORTING_BOT_VCARD )
1211
- . await ?
1212
- . first ( )
1213
- . context ( "Self reporting bot vCard does not contain a contact" ) ?;
1214
- mark_contact_id_as_verified ( self , contact_id, ContactId :: SELF ) . await ?;
1215
-
1216
- let chat_id = if let Some ( res) = ChatId :: lookup_by_contact ( self , contact_id) . await ? {
1217
- // Already exists, no need to create.
1218
- res
1219
- } else {
1220
- let chat_id = ChatId :: get_for_contact ( self , contact_id) . await ?;
1221
- chat_id
1222
- . set_visibility ( self , ChatVisibility :: Archived )
1223
- . await ?;
1224
- chat:: set_muted ( self , chat_id, MuteDuration :: Forever ) . await ?;
1225
- chat_id
1226
- } ;
1227
-
1228
- chat_id
1229
- . set_protection ( self , ProtectionStatus :: Protected , time ( ) , Some ( contact_id) )
1230
- . await ?;
1231
-
1232
- let mut msg = Message :: new ( Viewtype :: File ) ;
1233
- msg. set_text (
1234
- "The attachment contains anonymous usage statistics, \
1235
- because you enabled this in the settings. \
1236
- This helps us improve the security of Delta Chat. \
1237
- See TODO[blog post] for more information."
1238
- . to_string ( ) ,
1239
- ) ;
1240
- msg. set_file_from_bytes (
1241
- self ,
1242
- "statistics.txt" ,
1243
- self . get_self_report ( ) . await ?. as_bytes ( ) ,
1244
- Some ( "text/plain" ) ,
1245
- ) ?;
1246
-
1247
- crate :: chat:: send_msg ( self , chat_id, & mut msg)
1248
- . await
1249
- . context ( "Failed to send self_reporting message" )
1250
- . log_err ( self )
1251
- . ok ( ) ;
1252
-
1253
- Ok ( chat_id)
1254
- }
1255
-
1256
1065
/// Get a list of fresh, unmuted messages in unblocked chats.
1257
1066
///
1258
1067
/// The list starts with the most recent message
0 commit comments