Răsfoiți Sursa

remove unneeded occurences of legacy SharedPrefrences + fix subject encoding in fetchMails function

Noah Vogt 3 ani în urmă
părinte
comite
fc009013dc

+ 1 - 11
app/src/main/java/com/noahvogt/miniprojekt/MainActivity.java

@@ -76,7 +76,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
     private AlertDialog dialog;
     private EditText newemail_name, newemail_email, newemail_password; /* may not be private */
 
-    SharedPreferences preferences, mailServerCredentials;
+    SharedPreferences mailServerCredentials;
 
     /* leave descriptor empty */
     public MainActivity() {}
@@ -124,8 +124,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
         });
 
         /* invoke preferences */
-        preferences = getSharedPreferences("UserPreferences", Context.MODE_PRIVATE);
-
         mailServerCredentials = getSharedPreferences("Credentials", Context.MODE_PRIVATE);
 
         /* invoke toolbar */
@@ -311,7 +309,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
     public void addNewAccountCredentials(String name, String email, String password, int imapPort,
                                          int smtpPort, String imapHost, String smtpHost, DialogInterface dialogContext,
                                          boolean wantConnectionFailedDialog) {
-        SharedPreferences.Editor preferencesEditor = preferences.edit();
         credentialsEditor = mailServerCredentials.edit();
 
         /* connect to mail server */
@@ -319,12 +316,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
         if (MailFunctions.canConnect(MailFunctions.getImapHostFromEmail(email), email, password) == Boolean.TRUE) {
             showToast("was able to connect");
 
-            /* TODO: replace legacy strings down below completely with serialized settings json string */
-            preferencesEditor.putString("name", name);
-            preferencesEditor.putString("email", email);
-            preferencesEditor.putString("password", password);
-            preferencesEditor.apply();
-
             Gson gson = new Gson();
 
             /* read login credentials from SharedPreferences */
@@ -389,7 +380,6 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
         dialog = dialogBuilder.create();
         dialog.show();
 
-        SharedPreferences.Editor preferencesEditor = preferences.edit();
         credentialsEditor = mailServerCredentials.edit();
 
         /* store user input */

+ 5 - 4
app/src/main/python/mailFunctions.py

@@ -154,12 +154,13 @@ def fetchMails(connection, inbox):
             # set subject to an empty string when not found
             try:
                 if raw_string[1] == 'utf-8':
-                    subject = raw_string[0].raw_string('utf-8')
+                    subject = raw_string[0].decode('utf-8')
+                elif raw_string[1] == 'iso-8859-1':
+                    subject = raw_string[0].decode('iso-8859-1')
                 else:
-                    subject = raw_string[0].decode("iso-8859-1")
-                            #nonNoneList.append(str(item.decode("iso-8859-1")))
+                    subject = str(raw_string[0])
             except AttributeError:
-                subject=""
+                 subject = str(raw_string[0])
 
             output_dict['subject'] = subject
             output_dict['from'] = stringCompiling(raw_from)