structs.dart 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. //data structures
  2. class GetThreadResponse {
  3. final int id;
  4. final List<String> messages;
  5. final String subject;
  6. final DateTime date;
  7. final String from_name;
  8. final String from_address;
  9. final List<MailAddress> to;
  10. GetThreadResponse({
  11. required this.id,
  12. required this.messages,
  13. required this.subject,
  14. required this.date,
  15. required this.from_name,
  16. required this.from_address,
  17. required this.to,
  18. });
  19. factory GetThreadResponse.fromJson(Map<String, dynamic> json) {
  20. var toList = json['to'] as List<dynamic>;
  21. return GetThreadResponse (
  22. id: json['id'],
  23. messages: List<String>.from(json['messages']),
  24. subject: json['subject'],
  25. date: DateTime.parse(json['date']),
  26. from_name: json['from_name'],
  27. from_address: json['from_address'],
  28. to: toList.map((i)=> MailAddress.fromJson(i)).toList(),
  29. );
  30. }
  31. }
  32. class MailAddress {
  33. final String? name;
  34. final String address;
  35. MailAddress({this.name, required this.address});
  36. factory MailAddress.fromJson(Map<String, dynamic> json) {
  37. return MailAddress(
  38. name: json['name'],
  39. address: json['address'],
  40. );
  41. }
  42. @override
  43. String toString() {
  44. // TODO: implement toString
  45. return '${name} <${address}>';
  46. }
  47. }
  48. // //old data structure
  49. class SerializableMessage {
  50. final String name;
  51. final String from;
  52. final List<MailAddress> to;
  53. final List<MailAddress> cc;
  54. final String hash;
  55. final String subject;
  56. final String date;
  57. final int uid;
  58. final String list;
  59. final String id;
  60. final String in_reply_to;
  61. SerializableMessage({
  62. required this.name,
  63. required this.from,
  64. required this.to,
  65. required this.cc,
  66. required this.hash,
  67. required this.subject,
  68. required this.date,
  69. required this.uid,
  70. required this.list,
  71. required this.id,
  72. required this.in_reply_to,
  73. });
  74. factory SerializableMessage.fromJson(Map<String, dynamic> json) {
  75. var toList = json['to'] as List;
  76. var ccList = json['cc'] as List;
  77. return SerializableMessage(
  78. name: json['name'],
  79. from: json['from'],
  80. // to: json['name', 'address']
  81. to: toList.map((i) => MailAddress.fromJson(i)).toList(),
  82. cc: ccList.map((i) => MailAddress.fromJson(i)).toList(),
  83. // path: json['path'],
  84. hash: json['hash'],
  85. subject: json['subject'],
  86. date: json['date'],
  87. uid: json['uid'],
  88. list: json['list'],
  89. id: json['id'],
  90. in_reply_to: json['in_reply_to'],
  91. );
  92. }
  93. }