|
@@ -1,12 +1,10 @@
|
|
import 'package:crab_ui/structs.dart';
|
|
import 'package:crab_ui/structs.dart';
|
|
-import 'package:english_words/english_words.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:http/http.dart' as http;
|
|
import 'dart:convert';
|
|
import 'dart:convert';
|
|
import 'dart:ui_web' as ui;
|
|
import 'dart:ui_web' as ui;
|
|
-import 'dart:html' as html;
|
|
|
|
import 'augment.dart';
|
|
import 'augment.dart';
|
|
-import 'dart:js' as js;
|
|
|
|
|
|
+import 'dart:html' as html;
|
|
|
|
|
|
//data structure
|
|
//data structure
|
|
class MailAddress {
|
|
class MailAddress {
|
|
@@ -28,77 +26,28 @@ class MailAddress {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-// //data structure
|
|
|
|
-// class SerializableMessage {
|
|
|
|
-// final String name;
|
|
|
|
-// final String from;
|
|
|
|
-// final List<MailAddress> to;
|
|
|
|
-// final List<MailAddress> 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<String, dynamic> 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'],
|
|
|
|
-// );
|
|
|
|
-// }
|
|
|
|
-// }
|
|
|
|
-
|
|
|
|
class EmailPage extends StatefulWidget {
|
|
class EmailPage extends StatefulWidget {
|
|
const EmailPage({super.key});
|
|
const EmailPage({super.key});
|
|
final String title = 'Emails';
|
|
final String title = 'Emails';
|
|
|
|
|
|
@override
|
|
@override
|
|
- State<EmailPage> createState() => _EmailPageState();
|
|
|
|
|
|
+ State<EmailPage> createState() => EmailPageState();
|
|
}
|
|
}
|
|
|
|
|
|
-class _EmailPageState extends State<EmailPage> {
|
|
|
|
|
|
+class EmailPageState extends State<EmailPage> {
|
|
List emails = [];
|
|
List emails = [];
|
|
|
|
|
|
void _displayEmailsFromFolder(String folder) async {
|
|
void _displayEmailsFromFolder(String folder) async {
|
|
- // Map<String, List<SerializableMessage>> messagesMap = {};
|
|
|
|
List<GetThreadResponse> allEmails = []; //all the emails
|
|
List<GetThreadResponse> allEmails = []; //all the emails
|
|
|
|
|
|
try {
|
|
try {
|
|
var url = Uri.http(
|
|
var url = Uri.http(
|
|
- '127.0.0.1:3001', 'sorted_threads_by_date', {'folder': folder});
|
|
|
|
|
|
+ '127.0.0.1:3001', 'sorted_threads_by_date',
|
|
|
|
+ {'folder': folder,
|
|
|
|
+ 'limit': '10',
|
|
|
|
+ 'offset': '0'});
|
|
var response = await http.get(url);
|
|
var response = await http.get(url);
|
|
-
|
|
|
|
|
|
+ print(response);
|
|
if (response.statusCode == 200) {
|
|
if (response.statusCode == 200) {
|
|
List json = jsonDecode(response.body);
|
|
List json = jsonDecode(response.body);
|
|
for (var item in json.take(1)) {
|
|
for (var item in json.take(1)) {
|
|
@@ -106,11 +55,8 @@ class _EmailPageState extends State<EmailPage> {
|
|
if (item.length > 1 && item[0] is String && item[1] is List) {
|
|
if (item.length > 1 && item[0] is String && item[1] is List) {
|
|
List<int> threadIDs = List<int>.from(item[1]);
|
|
List<int> threadIDs = List<int>.from(item[1]);
|
|
for (var threadId in threadIDs) {
|
|
for (var threadId in threadIDs) {
|
|
- // print(threadId);
|
|
|
|
- // await fetchThreadMessages(threadId, allEmails);
|
|
|
|
await fetchThreads(threadId, allEmails);
|
|
await fetchThreads(threadId, allEmails);
|
|
}
|
|
}
|
|
- //TODO: get exact thread with new api endpoint from chosen thread?
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
@@ -124,39 +70,21 @@ class _EmailPageState extends State<EmailPage> {
|
|
setState(() {
|
|
setState(() {
|
|
emails = allEmails;
|
|
emails = allEmails;
|
|
});
|
|
});
|
|
- // print(emails[0]);
|
|
|
|
- // Print allEmails to debug its structure
|
|
|
|
- // print("allEmails: ${allEmails[0].messages}");
|
|
|
|
-
|
|
|
|
- // Convert allEmails to a list
|
|
|
|
}
|
|
}
|
|
-// }
|
|
|
|
|
|
|
|
Future<void> fetchThreads(
|
|
Future<void> fetchThreads(
|
|
- //complete
|
|
|
|
- int threadId,
|
|
|
|
- List<GetThreadResponse> allEmails) async {
|
|
|
|
|
|
+ int threadId, List<GetThreadResponse> allEmails) async {
|
|
try {
|
|
try {
|
|
var url =
|
|
var url =
|
|
Uri.http('127.0.0.1:3001', 'get_thread', {'id': threadId.toString()});
|
|
Uri.http('127.0.0.1:3001', 'get_thread', {'id': threadId.toString()});
|
|
var response = await http.get(url);
|
|
var response = await http.get(url);
|
|
- // print(response.body);
|
|
|
|
|
|
+
|
|
if (response.statusCode == 200) {
|
|
if (response.statusCode == 200) {
|
|
Map<String, dynamic> messagesJson = jsonDecode(response.body);
|
|
Map<String, dynamic> messagesJson = jsonDecode(response.body);
|
|
- // print(messagesJson);
|
|
|
|
- // List<String> messagesofThread = messagesJson['messages'];
|
|
|
|
- // messagesJson.map((mj) => GetThreadResponse.fromJson(mj)).toList();
|
|
|
|
- // List<GetThreadResponse> messages = messagesJson.values.map((mj) {
|
|
|
|
- // return GetThreadResponse.fromJson(mj as Map<String, dynamic>);
|
|
|
|
- // }).toList();
|
|
|
|
- // List<GetThreadResponse> thread =
|
|
|
|
- // messagesJson.map((mj) => GetThreadResponse.fromJson(mj)).toList();
|
|
|
|
GetThreadResponse threadResponse =
|
|
GetThreadResponse threadResponse =
|
|
GetThreadResponse.fromJson(messagesJson);
|
|
GetThreadResponse.fromJson(messagesJson);
|
|
|
|
|
|
- allEmails.add(
|
|
|
|
- threadResponse); //adds all the messages of the thread into all emails
|
|
|
|
- //perhaps should change
|
|
|
|
|
|
+ allEmails.add(threadResponse);
|
|
} else {
|
|
} else {
|
|
throw Exception(
|
|
throw Exception(
|
|
'Failed to fetch thread messages for thread ID: $threadId');
|
|
'Failed to fetch thread messages for thread ID: $threadId');
|
|
@@ -166,33 +94,12 @@ class _EmailPageState extends State<EmailPage> {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- // Future<void> fetchThreadMessages(
|
|
|
|
- // int threadId, List<SerializableMessage> allEmails) async {
|
|
|
|
- // try {
|
|
|
|
- // var url = Uri.http(
|
|
|
|
- // '127.0.0.1:3001', 'get_thread_messages', {'id': threadId.toString()});
|
|
|
|
-
|
|
|
|
- // var response = await http.get(url);
|
|
|
|
-
|
|
|
|
- // if (response.statusCode == 200) {
|
|
|
|
- // List<dynamic> messagesJson = jsonDecode(response.body);
|
|
|
|
- // List<SerializableMessage> messages =
|
|
|
|
- // messagesJson.map((mj) => SerializableMessage.fromJson(mj)).toList();
|
|
|
|
- // allEmails.addAll(messages);
|
|
|
|
- // } else {
|
|
|
|
- // throw Exception(
|
|
|
|
- // 'Failed to fetch thread messages for thread ID: $threadId');
|
|
|
|
- // }
|
|
|
|
- // } catch (e) {
|
|
|
|
- // print('Error fetching thread messages: $e');
|
|
|
|
- // }
|
|
|
|
- // }
|
|
|
|
-
|
|
|
|
Future<String> _getEmailContent(List<String> IDs) async {
|
|
Future<String> _getEmailContent(List<String> IDs) async {
|
|
String content = r"""
|
|
String content = r"""
|
|
""";
|
|
""";
|
|
|
|
|
|
try {
|
|
try {
|
|
|
|
+ //attaches email after email from a thread
|
|
for (var id in IDs) {
|
|
for (var id in IDs) {
|
|
var url = Uri.http('127.0.0.1:3001', 'email', {'id': id});
|
|
var url = Uri.http('127.0.0.1:3001', 'email', {'id': id});
|
|
|
|
|
|
@@ -200,16 +107,16 @@ class _EmailPageState extends State<EmailPage> {
|
|
|
|
|
|
if (response.statusCode == 200) {
|
|
if (response.statusCode == 200) {
|
|
content += response.body;
|
|
content += response.body;
|
|
|
|
+ content += "<p>new shit</p><br><br><br>";
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} catch (e) {
|
|
} catch (e) {
|
|
print('_getEmailContent caught error: $e');
|
|
print('_getEmailContent caught error: $e');
|
|
}
|
|
}
|
|
- print(content);
|
|
|
|
return content;
|
|
return content;
|
|
}
|
|
}
|
|
|
|
|
|
- Future<List<Widget>> _getDrawerItems() async {
|
|
|
|
|
|
+ Future<List<Widget>> getDrawerItems(BuildContext context) async {
|
|
List<String> drawerItems = [];
|
|
List<String> drawerItems = [];
|
|
|
|
|
|
try {
|
|
try {
|
|
@@ -217,7 +124,7 @@ class _EmailPageState extends State<EmailPage> {
|
|
var response = await http.get(url);
|
|
var response = await http.get(url);
|
|
drawerItems = List<String>.from(json.decode(response.body));
|
|
drawerItems = List<String>.from(json.decode(response.body));
|
|
} catch (e) {
|
|
} catch (e) {
|
|
- print('_getDrawerItems caught error: $e');
|
|
|
|
|
|
+ print('getDrawerItems caught error: $e');
|
|
}
|
|
}
|
|
|
|
|
|
List<Widget> drawerWidgets = [];
|
|
List<Widget> drawerWidgets = [];
|
|
@@ -248,7 +155,7 @@ class _EmailPageState extends State<EmailPage> {
|
|
drawer: Drawer(
|
|
drawer: Drawer(
|
|
child: FutureBuilder<List<Widget>>(
|
|
child: FutureBuilder<List<Widget>>(
|
|
future:
|
|
future:
|
|
- _getDrawerItems(), // call the async function to get the future
|
|
|
|
|
|
+ getDrawerItems(context), // call the async function to get the future
|
|
builder:
|
|
builder:
|
|
(BuildContext context, AsyncSnapshot<List<Widget>> snapshot) {
|
|
(BuildContext context, AsyncSnapshot<List<Widget>> snapshot) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
if (snapshot.connectionState == ConnectionState.waiting) {
|
|
@@ -312,18 +219,12 @@ class EmailListScreen extends StatelessWidget {
|
|
onTap: () async {
|
|
onTap: () async {
|
|
String emailContent =
|
|
String emailContent =
|
|
await getEmailContent(emails[index].messages);
|
|
await getEmailContent(emails[index].messages);
|
|
- String messages = emails[index].messages.toString();
|
|
|
|
String fromName = emails[index].from_name.toString();
|
|
String fromName = emails[index].from_name.toString();
|
|
String fromAddress = emails[index].from_address.toString();
|
|
String fromAddress = emails[index].from_address.toString();
|
|
String to = emails[index].to.toString();
|
|
String to = emails[index].to.toString();
|
|
- // String cc = emails[index].cc.toString();
|
|
|
|
- // String hash = emails[index].hash.toString();
|
|
|
|
String subject = emails[index].subject.toString();
|
|
String subject = emails[index].subject.toString();
|
|
String date = emails[index].date.toString();
|
|
String date = emails[index].date.toString();
|
|
- // String uid = emails[index].uid.toString();
|
|
|
|
- // String list = emails[index].list.toString();
|
|
|
|
String id = emails[index].id.toString();
|
|
String id = emails[index].id.toString();
|
|
- // String in_reply_to = emails[index].in_reply_to.toString();
|
|
|
|
|
|
|
|
Navigator.push(
|
|
Navigator.push(
|
|
context,
|
|
context,
|
|
@@ -333,17 +234,10 @@ class EmailListScreen extends StatelessWidget {
|
|
from: fromAddress,
|
|
from: fromAddress,
|
|
name: fromName,
|
|
name: fromName,
|
|
to: to,
|
|
to: to,
|
|
- // cc: cc,
|
|
|
|
- // hash: hash,
|
|
|
|
subject: subject,
|
|
subject: subject,
|
|
date: date,
|
|
date: date,
|
|
- // uid: uid,
|
|
|
|
- // list: list,
|
|
|
|
id: id,
|
|
id: id,
|
|
- // in_reply_to: in_reply_to,
|
|
|
|
- )
|
|
|
|
- //nada hpta
|
|
|
|
- ),
|
|
|
|
|
|
+ )),
|
|
);
|
|
);
|
|
});
|
|
});
|
|
},
|
|
},
|
|
@@ -357,39 +251,22 @@ class EmailListScreen extends StatelessWidget {
|
|
|
|
|
|
class EmailView extends StatefulWidget {
|
|
class EmailView extends StatefulWidget {
|
|
final String emailContent;
|
|
final String emailContent;
|
|
- // final String jsonEmail;
|
|
|
|
final String from;
|
|
final String from;
|
|
final String name;
|
|
final String name;
|
|
-
|
|
|
|
final String to;
|
|
final String to;
|
|
-
|
|
|
|
- // final String to;
|
|
|
|
- // final String cc;
|
|
|
|
- // final String hash;
|
|
|
|
final String subject;
|
|
final String subject;
|
|
final String date;
|
|
final String date;
|
|
- // final String uid;
|
|
|
|
- // final String list;
|
|
|
|
final String id;
|
|
final String id;
|
|
- // final String in_reply_to;
|
|
|
|
|
|
|
|
const EmailView({
|
|
const EmailView({
|
|
Key? key,
|
|
Key? key,
|
|
required this.emailContent,
|
|
required this.emailContent,
|
|
- // required this.jsonEmail,
|
|
|
|
required this.from,
|
|
required this.from,
|
|
required this.name,
|
|
required this.name,
|
|
required this.to,
|
|
required this.to,
|
|
-
|
|
|
|
- // required this.to,
|
|
|
|
- // required this.cc,
|
|
|
|
- // required this.hash,
|
|
|
|
required this.subject,
|
|
required this.subject,
|
|
required this.date,
|
|
required this.date,
|
|
- // required this.uid,
|
|
|
|
- // required this.list,
|
|
|
|
required this.id,
|
|
required this.id,
|
|
- // required this.in_reply_to
|
|
|
|
}) : super(key: key);
|
|
}) : super(key: key);
|
|
@override
|
|
@override
|
|
_EmailViewState createState() => _EmailViewState();
|
|
_EmailViewState createState() => _EmailViewState();
|
|
@@ -426,7 +303,7 @@ class _EmailViewState extends State<EmailView> {
|
|
AugmentClasses.handleJump(spanId);
|
|
AugmentClasses.handleJump(spanId);
|
|
}
|
|
}
|
|
|
|
|
|
- // void _invisibility(String )
|
|
|
|
|
|
+ // TODO: void _invisibility(String )
|
|
|
|
|
|
@override
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
Widget build(BuildContext context) {
|