Prechádzať zdrojové kódy

bugfixes, emailacount, configurations

Simon Hammer 3 rokov pred
rodič
commit
ed101bb85c

+ 94 - 0
app/schemas/com.noahvogt.miniprojekt.DataBase.EmailRoomDatabase/2.json

@@ -0,0 +1,94 @@
+{
+  "formatVersion": 1,
+  "database": {
+    "version": 2,
+    "identityHash": "22874ef127ac5669572671e40c064f64",
+    "entities": [
+      {
+        "tableName": "message_table",
+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `user` TEXT NOT NULL, `to` TEXT NOT NULL, `cc` TEXT, `bcc` TEXT, `fromEmail` TEXT NOT NULL, `date` TEXT NOT NULL, `subject` TEXT, `textContent` TEXT, `folder` TEXT NOT NULL, `seen` INTEGER NOT NULL)",
+        "fields": [
+          {
+            "fieldPath": "id",
+            "columnName": "id",
+            "affinity": "INTEGER",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mUser",
+            "columnName": "user",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mTo",
+            "columnName": "to",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mCc",
+            "columnName": "cc",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "mBcc",
+            "columnName": "bcc",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "mFrom",
+            "columnName": "fromEmail",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mDate",
+            "columnName": "date",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mSubject",
+            "columnName": "subject",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "mTextContent",
+            "columnName": "textContent",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "mFolder",
+            "columnName": "folder",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mSeen",
+            "columnName": "seen",
+            "affinity": "INTEGER",
+            "notNull": true
+          }
+        ],
+        "primaryKey": {
+          "columnNames": [
+            "id"
+          ],
+          "autoGenerate": true
+        },
+        "indices": [],
+        "foreignKeys": []
+      }
+    ],
+    "views": [],
+    "setupQueries": [
+      "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
+      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '22874ef127ac5669572671e40c064f64')"
+    ]
+  }
+}

+ 94 - 0
app/schemas/com.noahvogt.snailmail.DataBase.EmailRoomDatabase/1.json

@@ -0,0 +1,94 @@
+{
+  "formatVersion": 1,
+  "database": {
+    "version": 1,
+    "identityHash": "22874ef127ac5669572671e40c064f64",
+    "entities": [
+      {
+        "tableName": "message_table",
+        "createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `user` TEXT NOT NULL, `to` TEXT NOT NULL, `cc` TEXT, `bcc` TEXT, `fromEmail` TEXT NOT NULL, `date` TEXT NOT NULL, `subject` TEXT, `textContent` TEXT, `folder` TEXT NOT NULL, `seen` INTEGER NOT NULL)",
+        "fields": [
+          {
+            "fieldPath": "id",
+            "columnName": "id",
+            "affinity": "INTEGER",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mUser",
+            "columnName": "user",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mTo",
+            "columnName": "to",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mCc",
+            "columnName": "cc",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "mBcc",
+            "columnName": "bcc",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "mFrom",
+            "columnName": "fromEmail",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mDate",
+            "columnName": "date",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mSubject",
+            "columnName": "subject",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "mTextContent",
+            "columnName": "textContent",
+            "affinity": "TEXT",
+            "notNull": false
+          },
+          {
+            "fieldPath": "mFolder",
+            "columnName": "folder",
+            "affinity": "TEXT",
+            "notNull": true
+          },
+          {
+            "fieldPath": "mSeen",
+            "columnName": "seen",
+            "affinity": "INTEGER",
+            "notNull": true
+          }
+        ],
+        "primaryKey": {
+          "columnNames": [
+            "id"
+          ],
+          "autoGenerate": true
+        },
+        "indices": [],
+        "foreignKeys": []
+      }
+    ],
+    "views": [],
+    "setupQueries": [
+      "CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
+      "INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '22874ef127ac5669572671e40c064f64')"
+    ]
+  }
+}

+ 4 - 12
app/src/main/java/com/noahvogt/snailmail/MainActivity.java

@@ -544,7 +544,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
         /* connect to mail server */
         showToast("Probe Connection ...");
         if (MailFunctions.canConnect(imapHost, email, password) == Boolean.TRUE) {
-            showToast("was able to connect");
+            showToast("Was able to connect");
 
             Gson gson = new Gson();
 
@@ -664,6 +664,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
 
                 addNewAccountCredentials(name, email, password, 993, 587, MailFunctions.getImapHostFromEmail(email),
                         MailFunctions.getSmtpHostFromEmail(email), rootCreateNewEmailPopupDialog, true, headerView);
+                showToast("Downloading Messages");
                 mEmailViewModel.applyDownload();
                 userGlobal = email;
                 dialog.dismiss();
@@ -690,23 +691,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
     public boolean onOptionsItemSelected(MenuItem item) {
         switch (item.getItemId()){
             case R.id.action_information:
-                try {
-                    SimpleDateFormat rawDate = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
-                    SimpleDateFormat date = new SimpleDateFormat("dd.MM.yy");
-                    Date middleDate = rawDate.parse("Thu, 12 Aug 2021 19:21:13 +0000 (UTC)");
-                    String newDate = date.format(middleDate);
-                } catch (Throwable throwable) {
-                    Log.e(TAG, "Error formating date", throwable );
-                }
-
                 createInformation(false,null);
                 return true;
             case R.id.action_refresh:
+                showToast("Refreshing");
                 mEmailViewModel.applyDownload();
                 return true;
             case R.id.action_deletefolder:
-                showToast("clicked delete all");
-                mEmailViewModel.getAll(false);
+                showToast("Deleting all folders");
                 for (int delete = 0; delete < mEmailViewModel.getAll(false).size(); delete++){
                     mEmailViewModel.deleteMessage(mEmailViewModel.getAll(false).get(delete));
                 }

+ 10 - 4
app/src/main/java/com/noahvogt/snailmail/MessageCreateFragment.java

@@ -237,10 +237,16 @@ public class MessageCreateFragment extends DialogFragment implements PopupMenu.O
                 /* check for valid input */
                 if (MailFunctions.validateMessageBody(messageBodyObject) && MailFunctions.validateSubject(subjectObject) &&
                 MailFunctions.validateEmail(receivingAddressObject) && MailFunctions.validateEmail(sendingAddressObject)) {
-                    MailFunctions.sendStarttlsMail(smtpHost, sendingAddress, receivingAddress, password, messageBody,
-                            subject, ccStr, bccStr, smtpPort);
-                    Toast.makeText(getActivity(), "sending ... ", Toast.LENGTH_SHORT).show();
-                    dismiss();
+                    try {
+
+
+                        MailFunctions.sendStarttlsMail(smtpHost, sendingAddress, receivingAddress, password, messageBody,
+                                subject, ccStr, bccStr, smtpPort);
+                        Toast.makeText(getActivity(), "Sending ... ", Toast.LENGTH_SHORT).show();
+                        dismiss();
+                    }catch (com.chaquo.python.PyException pyException){
+                        Toast.makeText(getActivity(), "Couldn't send message", Toast.LENGTH_SHORT).show();
+                    }
                 } else {
                     Toast.makeText(getActivity(), "Please check your input", Toast.LENGTH_SHORT).show();
                 }

+ 4 - 3
app/src/main/java/com/noahvogt/snailmail/data/EmailViewModel.java

@@ -56,7 +56,9 @@ public class EmailViewModel extends AndroidViewModel {
     }
 
     public void setListAll(List<Message> messageListAll, String fragment){
-        System.out.println("setListAll: size messageListAll: " + messageListAll.size());
+        System.out.println("setListAll: size messageListAll input: " + messageListAll.size());
+        System.out.println("setListAll: fragment: " + fragment);
+        System.out.println("setListAll: variable inbox: " + inbox);
         if (sent == null && fragment.equals("Sent")){
             for (int i = 0; i < messageListAll.size(); i++) {
                 this.all.add(messageListAll.get(i));
@@ -89,8 +91,7 @@ public class EmailViewModel extends AndroidViewModel {
             }
             spam = fragment;
         }
-        System.out.println("SetListAll: List of All: " + all);
-        System.out.println("setListAll: size all: " + all.size());
+        System.out.println("setListAll: size all output: " + all.size());
     }
 
     public List<Message> getAll(boolean status){

+ 24 - 2
app/src/main/java/com/noahvogt/snailmail/data/MailFunctions.java

@@ -59,16 +59,26 @@ public class MailFunctions {
         String topLevelHost = email.substring(email.lastIndexOf("@") + 1);
         if (topLevelHost.endsWith("edubs.ch")) {
             return "teamwork.edubs.ch";
-
         } else if (topLevelHost.endsWith("yahoo.com")){
             return "imap.mail.yahoo.com";
-
         } else if (topLevelHost.endsWith("gmx.ch")){
             return "imap.gmx.net";
         } else if (topLevelHost.endsWith("gmx.de")){
             return "imap.gmx.net";
         } else if (topLevelHost.equals("noahvogt.com")) {
             return "mail.noahvogt.com";
+        }else if (topLevelHost.endsWith("outlook.com")) {
+            return "outlook.office365.com";
+        }else if (topLevelHost.endsWith("icloud.com")){
+            return "imap.mail.me.com";
+        }else if (topLevelHost.endsWith("outlook.ch")) {
+            return "outlook.office365.com";
+        }else if (topLevelHost.endsWith("hotmail.com")) {
+            return "outlook.office365.com";
+        }else if (topLevelHost.endsWith("hotmail.ch")) {
+            return "outlook.office365.com";
+        }else if (topLevelHost.endsWith("web.de")) {
+            return "imap.web.de ";
         } else {
                 return "imap." + topLevelHost;
         }
@@ -87,6 +97,18 @@ public class MailFunctions {
             return "mail.gmx.net";
         } else if (topLevelHost.endsWith("edubs.ch")) {
             return "smtp.edubs.ch";
+        }else if (topLevelHost.endsWith("outlook.com")) {
+            return "smtp-mail.outlook.com";
+        }else if (topLevelHost.endsWith("outlook.ch")) {
+            return "smtp-mail.outlook.com";
+        }else if (topLevelHost.endsWith("hotmail.com")) {
+            return "smtp-mail.outlook.com";
+        }else if (topLevelHost.endsWith("hotmail.ch")) {
+            return "smtp-mail.outlook.com";
+        }else if (topLevelHost.endsWith("icloud.com")){
+            return "smtp.mail.me.com";
+        }else if (topLevelHost.endsWith("web.de")){
+            return "smtp.web.de";
         } else {
             return "smtp." + topLevelHost;
         }

+ 0 - 47
app/src/main/java/com/noahvogt/snailmail/data/ReadInMailsActivity.java

@@ -1,47 +0,0 @@
-package com.noahvogt.snailmail.data;
-
-import android.content.Intent;
-import android.os.Bundle;
-import android.widget.Toast;
-
-import androidx.appcompat.app.AppCompatActivity;
-
-import com.noahvogt.snailmail.R;
-
-import java.util.List;
-
-public class ReadInMailsActivity extends AppCompatActivity {
-
-    String mEmail;
-    String mPassword;
-
-
-    @Override
-    protected void onCreate(Bundle savedInstanceState){
-        super.onCreate(savedInstanceState);
-        setContentView(R.layout.activity_main);
-
-        Intent intent = getIntent();
-        mEmail = intent.getStringExtra("Email");
-        mPassword = intent.getStringExtra("Password");
-
-        Toast.makeText(getBaseContext(),"Probe Connection ...", Toast.LENGTH_SHORT).show();
-        if (MailFunctions.canConnect(MailFunctions.getImapHostFromEmail(mEmail), mEmail, mPassword) == Boolean.TRUE) {
-            //showToast("was able to connect");
-
-            List folders = MailFunctions.listMailboxes(MailFunctions.getIMAPConnection(MailFunctions.getImapHostFromEmail(mEmail), mEmail, mPassword, 993));
-            for (int i = 0; i < folders.size(); i++) {
-                //showToast(folders.get(i).toString());
-                // TODO: select right folder to store, Synchronization
-                /*gives list of Message Objects/dictionaries */
-                //List p = MailFunctions.fetchMailsFromBox(
-                //        MailFunctions.getIMAPConnection(
-                //                MailFunctions.getImapHostFromEmail(mEmail), mEmail, mPassword),
-                //        folders.get(i).toString());
-                //System.out.println(folders.get(i).toString());
-                //System.out.println(p);
-            }
-        }
-
-    }
-}

+ 1 - 0
app/src/main/java/com/noahvogt/snailmail/ui/home/HomeFragment.java

@@ -54,6 +54,7 @@ public class HomeFragment extends Fragment implements CustomAdapter.SelectedMess
             /*get List of Message to show them onClick */
             adapter.getList(messages);
             /*gives list of messages to EmailViewModel */
+            System.out.println("HomeFragment List: "+messages);
             MainActivity.mEmailViewModel.setListAll(messages, "Inbox");
             //mEmailViewModel.getAllMessages();
         });

+ 3 - 17
app/src/main/java/com/noahvogt/snailmail/workers/DownloadWorker.java

@@ -85,9 +85,6 @@ public class DownloadWorker extends Worker {
                 List folders =  MailFunctions.listMailboxes(MailFunctions.getIMAPConnection(mImapHost,
                         mUser, mPassword, mImapPort));
 
-
-                //mEmailViewModel.getAll(true);
-
                 for (int i = 0; i < folders.size(); i++) {
                     String folderName;
                     String folderNow = folders.get(i).toString();
@@ -114,13 +111,10 @@ public class DownloadWorker extends Worker {
                         folderName = folders.get(i).toString();
                     }
 
-                    //mEmailViewModel.deleteFolder(folders.get(i).toString());
                     /* fetch and print draft messages */
                     String fetchedMails = MailFunctions.fetchMailsFromBox(MailFunctions.getIMAPConnection(mImapHost,
                             mUser, mPassword, mImapPort),
                             folders.get(i).toString(), folderName);
-                    //System.out.println("Folder: " + folders.get(i).toString()+ "\n Foldersize: " + folders.size());
-                    //System.out.println("Fetched Mails from Folder " + folders.get(i).toString() + ": \n"+ fetchedMails + "\n MAANCBJC");
 
                     /* parse messages in arraylist of Message class and loop through it */
                     Type messageType = new TypeToken<ArrayList<Message>>() {
@@ -129,23 +123,15 @@ public class DownloadWorker extends Worker {
                     for (int k = 0; k < messages.size(); k++) {
                         Message message = messages.get(k);
                         message.putUser(currentUser);
-                        /*
-                        System.out.println("oldDate: " + message.getDate());
+
                         SimpleDateFormat rawDate = new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss Z");
                         SimpleDateFormat date = new SimpleDateFormat("dd.MM.yy");
                         Date middleDate = rawDate.parse(message.getDate());
                         String newDate = date.format(middleDate);
-                        System.out.println("middle Date: " + middleDate);
-                        System.out.println("New Date: " + newDate);
-
-                         */
 
+                        message.putDate(newDate);
                         mEmailViewModel.insert(message);
-                        //TODO: make it work
-                        /*dosent wrok idk why*/
-                        //mEmailViewModel.updateDate(message.getId(), newDate);
-                        //System.out.println("Folder: " + folders.get(i).toString() + "\n IMPORTANT FOLDERS");
-                        //System.out.println("Size of this Folder: " + messages.size());
+
                     }
 
                 }