|
@@ -1,5 +1,3 @@
|
|
|
-// import 'dart:ffi';
|
|
|
-
|
|
|
import 'package:flutter/material.dart';
|
|
|
import 'package:http/http.dart' as http;
|
|
|
import 'dart:convert';
|
|
@@ -148,39 +146,11 @@ class _EmailPageState extends State<EmailPage> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- // Future<void> getEmailJson(String threadId) async {
|
|
|
- // // List< jsonTypeShit = "";
|
|
|
- // try {
|
|
|
- // var url = Uri.http(
|
|
|
- // '127.0.0.1:3001', 'get_thread_messages', {'id': threadId.toString()});
|
|
|
- // // print(url);
|
|
|
- // var response = await http.get(url);
|
|
|
- // // print(response.body);
|
|
|
- // if (response.statusCode == 200) {
|
|
|
- // List<dynamic> messagesJson = jsonDecode(response.body);
|
|
|
- // print(messagesJson);
|
|
|
- // print("1");
|
|
|
- // List<SerializableMessage> messages =
|
|
|
- // messagesJson.map((mj) => SerializableMessage.fromJson(mj)).toList();
|
|
|
- // // allEmails.addAll(messages);
|
|
|
-
|
|
|
- // print(messages);
|
|
|
- // // jsonTypeShit = messages;
|
|
|
- // } else {
|
|
|
- // throw Exception(
|
|
|
- // 'Failed to fetch thread messages for thread ID: $threadId');
|
|
|
- // }
|
|
|
- // } catch (e) {
|
|
|
- // print('Error fetching thread messages: $e');
|
|
|
- // }
|
|
|
- // // return(messages)
|
|
|
- // }
|
|
|
-
|
|
|
Future<String> _getEmailContent(String id) async {
|
|
|
String content = r"""
|
|
|
|
|
|
""";
|
|
|
- String restcontent = "";
|
|
|
+ // String restcontent = "";
|
|
|
try {
|
|
|
var url = Uri.http('127.0.0.1:3001', 'email', {'id': id});
|
|
|
// print(url);
|
|
@@ -189,28 +159,50 @@ class _EmailPageState extends State<EmailPage> {
|
|
|
if (response.statusCode == 200) {
|
|
|
print('ok');
|
|
|
content = response.body;
|
|
|
- try {
|
|
|
- var restUrl =
|
|
|
- Uri.http('127.0.0.1:3001', 'get_thread_messages', {'id': id});
|
|
|
- print(restUrl);
|
|
|
- var restresponse = await http.get(restUrl);
|
|
|
- print(restresponse.statusCode);
|
|
|
- if (restresponse.statusCode == 200) {
|
|
|
- print("ok squared");
|
|
|
- restcontent = restresponse.body;
|
|
|
- }
|
|
|
- } catch (i) {
|
|
|
- print('jsoncontent caught error: $i');
|
|
|
- }
|
|
|
+ // try {
|
|
|
+ // var restUrl =
|
|
|
+ // Uri.http('127.0.0.1:3001', 'get_thread_messages', {'id': id});
|
|
|
+ // // print(restUrl);
|
|
|
+ // var restresponse = await http.get(restUrl);
|
|
|
+ // // print(restresponse.statusCode);
|
|
|
+ // if (restresponse.statusCode == 200) {
|
|
|
+ // print("ok squared");
|
|
|
+ // // restcontent = restresponse.body;
|
|
|
+ // }
|
|
|
+ // } catch (i) {
|
|
|
+ // print('jsoncontent caught error: $i');
|
|
|
+ // }
|
|
|
}
|
|
|
} catch (e) {
|
|
|
print('_getEmailContent caught error: $e');
|
|
|
}
|
|
|
// print(content);
|
|
|
- print(restcontent);
|
|
|
+ // print(restcontent);
|
|
|
return content;
|
|
|
}
|
|
|
|
|
|
+ Future<String> _getThreadMessagesJson(String threadId) async {
|
|
|
+ String jsonResponse = "";
|
|
|
+
|
|
|
+ try {
|
|
|
+ var url =
|
|
|
+ Uri.http('127.0.0.1:3001', 'get_thread_messages', {'id': threadId});
|
|
|
+ // print(url);
|
|
|
+ var response = await http.get(url);
|
|
|
+ // print(response.statusCode);
|
|
|
+ // print(response.body);
|
|
|
+ if (response.statusCode == 200) {
|
|
|
+ jsonResponse = response.body; // Here you get the JSON response
|
|
|
+ } else {
|
|
|
+ throw Exception('Failed to load thread messages');
|
|
|
+ }
|
|
|
+ } catch (e) {
|
|
|
+ print('_getThreadMessagesJson caught error: $e');
|
|
|
+ }
|
|
|
+
|
|
|
+ return jsonResponse; // Returns the JSON string
|
|
|
+ }
|
|
|
+
|
|
|
Future<List<Widget>> _getDrawerItems() async {
|
|
|
List<String> drawerItems = [];
|
|
|
|
|
@@ -270,7 +262,10 @@ class _EmailPageState extends State<EmailPage> {
|
|
|
},
|
|
|
),
|
|
|
),
|
|
|
- body: EmailListScreen(emails: emails, getEmailContent: _getEmailContent),
|
|
|
+ body: EmailListScreen(
|
|
|
+ emails: emails,
|
|
|
+ getEmailContent: _getEmailContent,
|
|
|
+ getJsonEmail: _getThreadMessagesJson),
|
|
|
);
|
|
|
}
|
|
|
}
|
|
@@ -278,8 +273,12 @@ class _EmailPageState extends State<EmailPage> {
|
|
|
class EmailListScreen extends StatelessWidget {
|
|
|
final List emails;
|
|
|
final Future<String> Function(String) getEmailContent;
|
|
|
+ final Future<String> Function(String) getJsonEmail;
|
|
|
|
|
|
- EmailListScreen({required this.emails, required this.getEmailContent});
|
|
|
+ EmailListScreen(
|
|
|
+ {required this.emails,
|
|
|
+ required this.getEmailContent,
|
|
|
+ required this.getJsonEmail});
|
|
|
|
|
|
@override
|
|
|
Widget build(BuildContext context) {
|
|
@@ -303,11 +302,28 @@ class EmailListScreen extends StatelessWidget {
|
|
|
trailing: Text(emails[index].date.toString()),
|
|
|
onTap: () async {
|
|
|
String emailContent = await getEmailContent(emails[index].id);
|
|
|
+ String jsonContent =
|
|
|
+ await getJsonEmail(emails[index].uid.toString());
|
|
|
+ // print(emails[index]);
|
|
|
+ String from = emails[index].from;
|
|
|
+ String name = emails[index].name;
|
|
|
+ String to = emails[index].to;
|
|
|
+ String cc = emails[index].cc;
|
|
|
+ String hash = emails[index].hash;
|
|
|
+ String subject = emails[index].subject;
|
|
|
+ String date = emails[index].date;
|
|
|
+ String uid = emails[index].uid;
|
|
|
+ String list = emails[index].list;
|
|
|
+ String id = emails[index].id;
|
|
|
+ String in_reply_to = emails[index].in_reply_to;
|
|
|
+ // String jsonbuilt =
|
|
|
Navigator.push(
|
|
|
context,
|
|
|
MaterialPageRoute(
|
|
|
- builder: (context) =>
|
|
|
- EmailView(emailContent: emailContent)),
|
|
|
+ builder: (context) => EmailView(
|
|
|
+ emailContent: emailContent,
|
|
|
+ jsonEmail: jsonContent,
|
|
|
+ )),
|
|
|
);
|
|
|
});
|
|
|
},
|
|
@@ -321,106 +337,21 @@ class EmailListScreen extends StatelessWidget {
|
|
|
|
|
|
class EmailView extends StatefulWidget {
|
|
|
final String emailContent;
|
|
|
+ final String jsonEmail;
|
|
|
+
|
|
|
|
|
|
- const EmailView({Key? key, required this.emailContent}) : super(key: key);
|
|
|
+
|
|
|
+ const EmailView(
|
|
|
+ {Key? key, required this.emailContent, required this.jsonEmail})
|
|
|
+ : super(key: key);
|
|
|
@override
|
|
|
_EmailViewState createState() => _EmailViewState();
|
|
|
-
|
|
|
- // @override
|
|
|
- // void initState(){
|
|
|
- // ui.platformViewRegistry.registerViewFactory(
|
|
|
- // 'html-view33',
|
|
|
- // (int viewId) => html.IFrameElement()
|
|
|
- // ..width = '100%'
|
|
|
- // ..height = '100%'
|
|
|
- // ..srcdoc = emailContent
|
|
|
- // ..style.border = 'none');
|
|
|
}
|
|
|
|
|
|
-// @override
|
|
|
-// Widget build(BuildContext context) {
|
|
|
-// return Scaffold(
|
|
|
-// appBar: AppBar(
|
|
|
-// title: Text('Email Content'),
|
|
|
-// ),
|
|
|
-// // body: SingleChildScrollView(
|
|
|
-// // child: Padding(
|
|
|
-// // padding: const EdgeInsets.all(16.0),
|
|
|
-// // child: HtmlWidget(
|
|
|
-// // emailContent,
|
|
|
-// // onErrorBuilder: (context, element, error) =>
|
|
|
-// // Text('$element error: $error'),
|
|
|
-// // onLoadingBuilder: (context, element, loadingProgress) =>
|
|
|
-// // CircularProgressIndicator(),
|
|
|
-// // renderMode: RenderMode.column,
|
|
|
-// // // webView: true,
|
|
|
-// // ),
|
|
|
-// // ),
|
|
|
-// // ),
|
|
|
-// // body: Center(
|
|
|
-// // child: Html(
|
|
|
-// // data: emailContent
|
|
|
-// // )
|
|
|
-// // ,
|
|
|
-// // ),
|
|
|
-// body: Center(
|
|
|
-// child: HtmlElementView(viewType: 'html-view33',),
|
|
|
-// ),
|
|
|
-
|
|
|
-// );
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// class HtmlContentWidget
|
|
|
-
|
|
|
-// class HtmlIFrameView extends StatelessWidget {
|
|
|
-// final String emailContent;
|
|
|
-
|
|
|
-// const HtmlIFrameView({required this.emailContent});
|
|
|
-
|
|
|
-// @override
|
|
|
-// Widget build(BuildContext context) {
|
|
|
-// return HtmlElementView(viewType: 'html-view');
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// class HtmlElementView extends StatelessWidget {
|
|
|
-// final String emailContent;
|
|
|
-
|
|
|
-// const HtmlElementView({required this.emailContent});
|
|
|
-
|
|
|
-// @override
|
|
|
-// Widget build(BuildContext context) {
|
|
|
-// return IFrameElementWidget(emailContent: emailContent);
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// class IFrameElementWidget extends StatelessWidget {
|
|
|
-// final String emailContent;
|
|
|
-
|
|
|
-// const IFrameElementWidget({required this.emailContent});
|
|
|
-
|
|
|
-// @override
|
|
|
-// Widget build(BuildContext context) {
|
|
|
-// ui.platformViewRegistry.registerViewFactory(
|
|
|
-// 'html-view',
|
|
|
-// (int viewId) => html.IFrameElement()
|
|
|
-// ..width = '100%'
|
|
|
-// ..height = '100%'
|
|
|
-// ..srcdoc = emailContent
|
|
|
-// ..style.border = 'none',
|
|
|
-// );
|
|
|
-// return HtmlElementView(
|
|
|
-// viewType: 'html-view',
|
|
|
-// );
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
class _EmailViewState extends State<EmailView> {
|
|
|
@override
|
|
|
void initState() {
|
|
|
super.initState();
|
|
|
-
|
|
|
ui.platformViewRegistry.registerViewFactory(
|
|
|
'html-view33',
|
|
|
(int viewId) => html.IFrameElement()
|
|
@@ -435,10 +366,12 @@ class _EmailViewState extends State<EmailView> {
|
|
|
Widget build(BuildContext context) {
|
|
|
return Scaffold(
|
|
|
appBar: AppBar(
|
|
|
- title: Text('email content'),
|
|
|
+ title: Text(widget.name),
|
|
|
),
|
|
|
- body: HtmlElementView(
|
|
|
- viewType: 'html-view33',
|
|
|
+ body: Container(
|
|
|
+ child: HtmlElementView(
|
|
|
+ viewType: 'html-view33',
|
|
|
+ ),
|
|
|
),
|
|
|
);
|
|
|
}
|