diff --git a/lib/api_service.dart b/lib/api_service.dart index ecd5a83..f40f93d 100644 --- a/lib/api_service.dart +++ b/lib/api_service.dart @@ -9,8 +9,8 @@ import 'package:http/http.dart' as http; import 'dart:convert'; class ApiService { - static String ip = ""; - static String port = ""; + static String ip = '127.0.0.1'; + static String port = "3001"; static List threadAttachments = []; //holds attachments of the thread static String currFolder = ""; @@ -169,7 +169,7 @@ class ApiService { Future moveEmail( //only moves the first email of the thread //or perhaps should do the last String fromFolder, - String thread_id, + String thread_id, //uid String toFolder) async { var url = Uri.http('$ip:$port', 'move_email'); @@ -185,7 +185,7 @@ class ApiService { Map requestBody = { 'from': fromFolder, 'uid': firstMail.uid.toString(), - 'to': toFolder, + 'to': "Deleted Crabmail", }; try { @@ -356,7 +356,7 @@ class ApiService { if (response.statusCode == 200) { counter += 1; Map json = jsonDecode(response.body); - + MDofThread.add(json['md'] ?? ''); try { List attachments = @@ -374,7 +374,67 @@ class ApiService { } catch (e) { print('_getMDContent caught error: $e'); } - + print("IDS inside fetch md content $IDsString"); + return MDofThread; } + + Future 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 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 deleteEmail(String from_folder, int thread_id) async { + // post + try { + List mailsInSerializable = + await this.threadsInSerializable(thread_id.toString()); + + if (mailsInSerializable.isEmpty) { + return false; + } + Map 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; + } + } }