added mark as seen or unseen api call and deleteEmail, which only moves it to a folder called Deleted Crabmail
This commit is contained in:
parent
b79d68c7a2
commit
ab0adf62e4
@ -9,8 +9,8 @@ import 'package:http/http.dart' as http;
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
|
||||||
class ApiService {
|
class ApiService {
|
||||||
static String ip = "";
|
static String ip = '127.0.0.1';
|
||||||
static String port = "";
|
static String port = "3001";
|
||||||
static List<AttachmentResponse> threadAttachments =
|
static List<AttachmentResponse> threadAttachments =
|
||||||
[]; //holds attachments of the thread
|
[]; //holds attachments of the thread
|
||||||
static String currFolder = "";
|
static String currFolder = "";
|
||||||
@ -169,7 +169,7 @@ class ApiService {
|
|||||||
Future<bool> moveEmail(
|
Future<bool> moveEmail(
|
||||||
//only moves the first email of the thread //or perhaps should do the last
|
//only moves the first email of the thread //or perhaps should do the last
|
||||||
String fromFolder,
|
String fromFolder,
|
||||||
String thread_id,
|
String thread_id, //uid
|
||||||
String toFolder) async {
|
String toFolder) async {
|
||||||
var url = Uri.http('$ip:$port', 'move_email');
|
var url = Uri.http('$ip:$port', 'move_email');
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ class ApiService {
|
|||||||
Map<String, String> requestBody = {
|
Map<String, String> requestBody = {
|
||||||
'from': fromFolder,
|
'from': fromFolder,
|
||||||
'uid': firstMail.uid.toString(),
|
'uid': firstMail.uid.toString(),
|
||||||
'to': toFolder,
|
'to': "Deleted Crabmail",
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -356,7 +356,7 @@ class ApiService {
|
|||||||
if (response.statusCode == 200) {
|
if (response.statusCode == 200) {
|
||||||
counter += 1;
|
counter += 1;
|
||||||
Map<String, dynamic> json = jsonDecode(response.body);
|
Map<String, dynamic> json = jsonDecode(response.body);
|
||||||
|
|
||||||
MDofThread.add(json['md'] ?? '');
|
MDofThread.add(json['md'] ?? '');
|
||||||
try {
|
try {
|
||||||
List<AttachmentInfo> attachments =
|
List<AttachmentInfo> attachments =
|
||||||
@ -374,7 +374,67 @@ class ApiService {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
print('_getMDContent caught error: $e');
|
print('_getMDContent caught error: $e');
|
||||||
}
|
}
|
||||||
|
print("IDS inside fetch md content $IDsString");
|
||||||
|
|
||||||
return MDofThread;
|
return MDofThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> markAsSeen(int thread_id) async {
|
||||||
|
try {
|
||||||
|
var url = Uri.http(
|
||||||
|
'$ip:$port', 'post_seen_thread', {'id': thread_id.toString()});
|
||||||
|
var response = await http.get(url);
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
var result = response.body;
|
||||||
|
print("data $result");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print("markAsSeen failed $e");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> markAsUnseen(int thread_id) async {
|
||||||
|
try {
|
||||||
|
var url = Uri.http(
|
||||||
|
'$ip:$port', 'post_unseen_thread', {'id': thread_id.toString()});
|
||||||
|
var response = await http.get(url);
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
var result = response.body;
|
||||||
|
print("data $result");
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print("markAsUnseen failed $e");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> deleteEmail(String from_folder, int thread_id) async {
|
||||||
|
// post
|
||||||
|
try {
|
||||||
|
List<SerializableMessage> mailsInSerializable =
|
||||||
|
await this.threadsInSerializable(thread_id.toString());
|
||||||
|
|
||||||
|
if (mailsInSerializable.isEmpty) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
Map<String, String> requestBody = {"from": from_folder, "uid": mailsInSerializable.first.uid.toString(), "to": "not used"};
|
||||||
|
|
||||||
|
//delete the email that is given to the
|
||||||
|
var url = Uri.http("$ip:$port", 'delete_email');
|
||||||
|
var response = await http.post(url,
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: jsonEncode(requestBody));
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
print("response body: ${response.body}");
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
print("not 200: ${response.body}");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
print("error in deleteEmail $e");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user