diff --git a/lib/api_service.dart b/lib/api_service.dart index 8136798..7ba5512 100644 --- a/lib/api_service.dart +++ b/lib/api_service.dart @@ -13,7 +13,7 @@ class ApiService { Future> fetchEmailsFromFolder( String folder, int pagenitaion) async { try { - var url = Uri.http('127.0.0.1:3001', 'sorted_threads_by_date', { + var url = Uri.http('0.0.0.0:3001', 'sorted_threads_by_date', { 'folder': folder, 'limit': '50', 'offset': pagenitaion.toString(), @@ -49,7 +49,7 @@ class ApiService { List allEmails) async { try { var url = - Uri.http('127.0.0.1:3001', 'get_thread', {'id': threadId.toString()}); + Uri.http('0.0.0.0:3001', 'get_thread', {'id': threadId.toString()}); var response = await http.get(url); if (response.statusCode == 200) { @@ -70,15 +70,16 @@ class ApiService { Future> sonicSearch( String list, int limit, int offset, String query) async { try { - var url = Uri.http('127.0.0.1:3001', 'search', { + var url = Uri.http('0.0.0.0:3001', 'search_emails', { 'list': list, 'limit': limit.toString(), 'offset': offset.toString(), 'query': query }); + print(url); var response = await http.get(url); - + print(response); if (response.statusCode == 200) { List messagesJson = json.decode(response.body); List messages = @@ -86,6 +87,7 @@ class ApiService { return messages; } + print(response.statusCode); } catch (e) { print("caught $e"); } @@ -99,12 +101,17 @@ class ApiService { try { //attaches email after email from a thread for (var id in IDs) { - var url = Uri.http('127.0.0.1:3001', 'email', {'id': id}); + var url = Uri.http('0.0.0.0:3001', 'email', {'id': id}); var response = await http.get(url); if (response.statusCode == 200) { content += response.body; + try { + getAttachmentsInfo("INBOX", id); + } catch (innerError) { + print('_getAttachment info caught error $innerError'); + } content += "
"; } } @@ -121,7 +128,7 @@ class ApiService { Future> fetchFolders() async { try { - var url = Uri.http('127.0.0.1:3001', 'folders'); + var url = Uri.http('0.0.0.0:3001', 'folders'); var response = await http.get(url); return List.from(json.decode(response.body)); } catch (e) { @@ -131,7 +138,7 @@ class ApiService { } Future createFolder(String folderName) async { - var url = Uri.http('127.0.0.1:3001', 'create_folder'); + var url = Uri.http('0.0.0.0:3001', 'create_folder'); Map requestBody = {'name': folderName}; @@ -154,7 +161,7 @@ class ApiService { } Future deleteFolder(String folderName) async { - var url = Uri.http('127.0.0.1:3001', 'delete_folder'); + var url = Uri.http('0.0.0.0:3001', 'delete_folder'); Map requestBody = {'name': folderName}; @@ -175,6 +182,41 @@ class ApiService { print('error making post req: $e'); } } + + Future logIn(String json) async { + // var url = Uri.https('') + // try{ + // String response = await http.post( + // url + // ); + // } + + return false; + } + + Future> getAttachmentsInfo( + String folder, String email_id) async { + try { + var url = Uri.http('0.0.0.0:3001', 'get_attachments_info', + {'folder': folder, 'email_id': email_id}); + print(url); + var response = await http.get(url); + print("response $response"); + if (response.statusCode == 200) { + var result = response.body; + List attachmentList = json.decode(result); + print("attachment list $attachmentList"); + List attachments = + attachmentList.map((al) => AttachmentInfo.fromJson(al)).toList(); + print("attachments $attachments"); + + return attachments; + } + } catch (e) { + print(e); + } + return []; + } } class EmailView extends StatefulWidget { diff --git a/lib/main.dart b/lib/main.dart index 081af44..da90a50 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -1,14 +1,12 @@ import 'package:crab_ui/contact.dart'; import 'package:flutter/material.dart'; import 'home_page.dart'; -// import 'api_service.dart'; import 'login.dart'; -import 'email.dart'; + void main() { WidgetsFlutterBinding.ensureInitialized(); - // debugPaintSizeEnabled = true; - runApp( HyM()); + runApp(HyM()); } class HyM extends StatelessWidget { @@ -22,14 +20,12 @@ class HyM extends StatelessWidget { theme: ThemeData.light(), title: 'HyM', // home: HomeScreen(), - // home: HomeScreen(), initialRoute: "/", routes: { "/": (context) => SplashScreen(), "/login": (context) => const LoginPage(), "/home": (context) => HomeScreen(), - // "/email": (context) => EmailPage(), "/contacts": (context) => ContactsPage(), }, ); diff --git a/lib/structs.dart b/lib/structs.dart index 9bc3ecf..6eb1c17 100644 --- a/lib/structs.dart +++ b/lib/structs.dart @@ -21,14 +21,14 @@ class GetThreadResponse { factory GetThreadResponse.fromJson(Map json) { var toList = json['to'] as List; - return GetThreadResponse ( + return GetThreadResponse( id: json['id'], messages: List.from(json['messages']), subject: json['subject'], date: DateTime.parse(json['date']), from_name: json['from_name'], from_address: json['from_address'], - to: toList.map((i)=> MailAddress.fromJson(i)).toList(), + to: toList.map((i) => MailAddress.fromJson(i)).toList(), ); } } @@ -51,6 +51,7 @@ class MailAddress { return '${name} <${address}>'; } } + // //old data structure class SerializableMessage { final String name; @@ -100,4 +101,20 @@ class SerializableMessage { in_reply_to: json['in_reply_to'], ); } -} \ No newline at end of file +} + +class AttachmentInfo { + final String name; + final int size; + final String path; + + AttachmentInfo({required this.name, required this.size, required this.path}); + + factory AttachmentInfo.fromJson(Map json) { + return AttachmentInfo( + name: json['name'], + size: json['size'], + path: json['path'], + ); + } +} diff --git a/pubspec.yaml b/pubspec.yaml index 9bc58aa..de4abb5 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -17,6 +17,7 @@ dependencies: shared_preferences: ^2.0.6 encrypt: ^5.0.0 pointycastle: ^3.4.0 + mime: ^1.0.3 english_words: ^4.0.0 provider: ^6.0.0