//data structures class GetThreadResponse { final int id; final List messages; final String subject; final DateTime date; final String from_name; final String from_address; final List to; GetThreadResponse({ required this.id, required this.messages, required this.subject, required this.date, required this.from_name, required this.from_address, required this.to, }); factory GetThreadResponse.fromJson(Map json) { var toList = json['to'] as List; return GetThreadResponse ( id: json['id'], messages: List.from(json['messages']), subject: json['subject'], date: DateTime.parse(json['date']), from_name: json['from_name'], from_address: json['from_address'], to: toList.map((i)=> MailAddress.fromJson(i)).toList(), ); } } class MailAddress { final String? name; final String address; MailAddress({this.name, required this.address}); factory MailAddress.fromJson(Map json) { return MailAddress( name: json['name'], address: json['address'], ); } @override String toString() { // TODO: implement toString return '${name} <${address}>'; } } // //old data structure class SerializableMessage { final String name; final String from; final List to; final List cc; final String hash; final String subject; final String date; final int uid; final String list; final String id; final String in_reply_to; SerializableMessage({ required this.name, required this.from, required this.to, required this.cc, required this.hash, required this.subject, required this.date, required this.uid, required this.list, required this.id, required this.in_reply_to, }); factory SerializableMessage.fromJson(Map json) { var toList = json['to'] as List; var ccList = json['cc'] as List; return SerializableMessage( name: json['name'], from: json['from'], // to: json['name', 'address'] to: toList.map((i) => MailAddress.fromJson(i)).toList(), cc: ccList.map((i) => MailAddress.fromJson(i)).toList(), // path: json['path'], hash: json['hash'], subject: json['subject'], date: json['date'], uid: json['uid'], list: json['list'], id: json['id'], in_reply_to: json['in_reply_to'], ); } }