Browse Source

fix: gmail authentication over non-oAuth

closes: https://framagit.org/dystopia-project/simple-email/-/issues/39
main
Distopico Vegan 4 years ago
parent
commit
15cc220fb0
No known key found for this signature in database GPG Key ID: 98093A8072546BF3
7 changed files with 624 additions and 567 deletions
  1. +51
    -8
      app/src/main/java/org/dystopia/email/FragmentAccount.java
  2. +1
    -1
      app/src/main/java/org/dystopia/email/ViewButtonColor.java
  3. +560
    -545
      app/src/main/res/layout/fragment_account.xml
  4. +2
    -0
      app/src/main/res/values-en/strings.xml
  5. +1
    -1
      app/src/main/res/values/dimens.xml
  6. +3
    -1
      app/src/main/res/values/strings.xml
  7. +6
    -11
      docs/FAQ.md

+ 51
- 8
app/src/main/java/org/dystopia/email/FragmentAccount.java View File

@ -40,8 +40,12 @@ import android.os.Handler;
import android.preference.PreferenceManager;
import android.text.Editable;
import android.text.Html;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
@ -60,6 +64,7 @@ import android.widget.Spinner;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.constraintlayout.widget.Group;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.FragmentResultListener;
@ -100,7 +105,7 @@ public class FragmentAccount extends FragmentEx {
private TextInputLayout tilPassword;
private Button btnAuthorize;
private TextView tvGmailNote;
private Button btnAdvanced;
private TextView tvName;
@ -184,6 +189,7 @@ public class FragmentAccount extends FragmentEx {
tilPassword = view.findViewById(R.id.tilPassword);
btnAuthorize = view.findViewById(R.id.btnAuthorize);
tvGmailNote = view.findViewById(R.id.tvGmailNote);
btnAdvanced = view.findViewById(R.id.btnAdvanced);
etName = view.findViewById(R.id.etName);
@ -230,7 +236,18 @@ public class FragmentAccount extends FragmentEx {
cbInsecure.setVisibility(position == 1 && insecure ? View.VISIBLE : View.GONE);
grpAuthorize.setVisibility(position > 0 ? View.VISIBLE : View.GONE);
btnAuthorize.setVisibility(provider.type == null ? View.GONE : View.VISIBLE);
// TODO: since December 31, 2019 Gmail retricted the oAuth
// gmail scopes and it require privative google play services java libraries
// so, only with "insecure" app enabled is supported
// see: https://developers.google.com/terms/api-services-user-data-policy#additional-requirements-for-specific-api-scopes
//
// maybe with webview and a web library?
btnAuthorize.setVisibility(View.GONE);
tvGmailNote.setVisibility(View.GONE);
if (provider.type != null) {
tvGmailNote.setVisibility(View.VISIBLE);
tvGmailNote.setText(Html.fromHtml(getString(R.string.text_gmail_note)));
}
btnAdvanced.setVisibility(position > 0 ? View.VISIBLE : View.GONE);
if (position == 0) {
@ -354,6 +371,24 @@ public class FragmentAccount extends FragmentEx {
}
});
tvGmailNote.setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
Spanned htmlMessage = Html.fromHtml(getString(R.string.message_gmail_note));
final SpannableString dialogMessage = new SpannableString(htmlMessage);
Linkify.addLinks(dialogMessage, Linkify.WEB_URLS);
AlertDialog dialog = new DialogBuilderLifecycle(getContext(), getViewLifecycleOwner())
.setMessage(dialogMessage)
.setPositiveButton(android.R.string.ok, null)
.show();
((TextView) dialog.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}
}
);
btnAdvanced.setOnClickListener(
new View.OnClickListener() {
@Override
@ -420,9 +455,7 @@ public class FragmentAccount extends FragmentEx {
args.putString("port", etPort.getText().toString());
args.putString("user", etUser.getText().toString());
args.putString("password", tilPassword.getEditText().getText().toString());
args.putInt(
"auth_type",
authorized == null ? Helper.AUTH_TYPE_PASSWORD : provider.getAuthType());
args.putInt("auth_type", provider.getAuthType());
new SimpleTask<CheckResult>() {
@Override
@ -457,14 +490,24 @@ public class FragmentAccount extends FragmentEx {
Session isession = Session.getInstance(props, null);
isession.setDebug(true);
IMAPStore istore = null;
try {
istore = (IMAPStore) isession.getStore(starttls ? "imap" : "imaps");
String originalPassword = password;
try {
if (auth_type == Helper.AUTH_TYPE_GMAIL) {
password = Helper.refreshToken(context, "com.google", user, password);
}
istore.connect(host, Integer.parseInt(port), user, password);
} catch (AuthenticationFailedException ex) {
// Try normal imap access with gmail allowed "insecure" app enabled
if (auth_type == Helper.AUTH_TYPE_GMAIL) {
password = Helper.refreshToken(context, "com.google", user, password);
istore.connect(host, Integer.parseInt(port), user, password);
auth_type = Helper.AUTH_TYPE_PASSWORD;
args.putInt("auth_type", auth_type);
props = MessageHelper.getSessionProperties(auth_type, insecure);
isession = Session.getInstance(props, null);
istore = (IMAPStore) isession.getStore(starttls ? "imap" : "imaps");
istore.connect(host, Integer.parseInt(port), user, originalPassword);
} else {
throw ex;
}
@ -1183,7 +1226,7 @@ public class FragmentAccount extends FragmentEx {
}
}
},
null);
null);
break;
}
}


+ 1
- 1
app/src/main/java/org/dystopia/email/ViewButtonColor.java View File

@ -66,7 +66,7 @@ public class ViewButtonColor extends AppCompatButton {
GradientDrawable background = new GradientDrawable();
background.setColor(color);
background.setStroke(
ViewHelper.dp2px(getContext(), 1),
ViewHelper.dp2px(getContext(), 3),
Helper.resolveColor(getContext(), R.attr.colorSeparator));
background.setCornerRadius(50);
setBackground(background);


+ 560
- 545
app/src/main/res/layout/fragment_account.xml
File diff suppressed because it is too large
View File


+ 2
- 0
app/src/main/res/values-en/strings.xml View File

@ -263,4 +263,6 @@
<string name="title_reset">Reset</string>
<string name="title_color">Color</string>
<string name="title_cancel">Cancel</string>
<string name="text_gmail_note"><![CDATA[Require have plain IMAP authentication enabled <font color=\'#0055C7\'>More info</font>]]></string>
<string name="message_gmail_note"><![CDATA[Since January 2020 Gmail restricted the oAuth scopes, now requires authorization to be able to authenticate, we have plans to fix this and allow oAuth authentication without privative libraries.<br/><br/> As a temporary solution you need to allow IMAP authentication or how Google says <i>\"less secure apps\"</i>.<br/><br/><b>Instructions here:</b> https://support.google.com/accounts/answer/6010255</br>]]></string>
</resources>

+ 1
- 1
app/src/main/res/values/dimens.xml View File

@ -15,5 +15,5 @@
<dimen name="compose_padding">6dp</dimen>
<dimen name="input_height">40dp</dimen>
<dimen name="normal_size">40dp</dimen>
<dimen name="color_pick">24dp</dimen>
<dimen name="color_pick">40dp</dimen>
</resources>

+ 3
- 1
app/src/main/res/values/strings.xml View File

@ -2,7 +2,7 @@
<resources>
<string name="app_name" translatable="false">SimpleEmail</string>
<string name="app_label" translatable="false">Email</string>
<string name="app_copyright" translatable="false">Copyright Ⓒ 2018 by M. Bokhorst\nCopyright Ⓒ 2018 by Distopico (dystopia project) and contributors</string>
<string name="app_copyright" translatable="false">Copyright Ⓒ 2018 by M. Bokhorst\nCopyright Ⓒ 2018-2020 by Distopico (dystopia project) and contributors</string>
<string name="app_eula" translatable="false">This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses.</string>
<string name="fingerprint" translatable="false">BCB07BD93B29C1959C15F1CF6C3A2619BAF7A17</string>
@ -307,4 +307,6 @@
<string name="title_reset">Reset</string>
<string name="title_color">Color</string>
<string name="title_cancel">Cancel</string>
<string name="text_gmail_note"><![CDATA[Require have plain IMAP authentication enabled <font color=\'#0055C7\'>More info</font>]]></string>
<string name="message_gmail_note"><![CDATA[Since January 2020 Gmail restricted the oAuth scopes, now requires authorization to be able to authenticate, we have plans to fix this and allow oAuth authentication without privative libraries.<br/><br/> As a temporary solution you need to allow IMAP authentication or how Google says <i>\"less secure apps\"</i>.<br/><br/><b>Instructions here:</b> https://support.google.com/accounts/answer/6010255</br>]]></string>
</resources>

+ 6
- 11
docs/FAQ.md View File

@ -62,22 +62,17 @@ See also [this FAQ](#FAQ16).
Valid security certificates are officially signed (not self signed) and have matching a host name.
#### ~~What does 'no IDLE support' mean?~~
#### What does 'no IDLE support' mean?
~~Without [IMAP IDLE](https://en.wikipedia.org/wiki/IMAP_IDLE) emails need to be periodically fetched,~~
~~which is a waste of battery power and internet bandwidth and will delay notification of new emails.~~
~~Since the goal of SimpleEmail is to offer safe and fast email, providers without IMAP IDLE are not supported.~~
~~You should consider this a problem of the provider, not of the app.~~
~~Almost all email providers offer IMAP IDLE, with as notable exception Yahoo!~~
Without [IMAP IDLE](https://en.wikipedia.org/wiki/IMAP_IDLE) emails need to be periodically fetched.
#### How can I login to Gmail / G suite?
Preferably select Gmail as provider and select an account on your device.
Since January 2020 Gmail restricted the scopes, now requires authorization 'oAuth' to be able to authenticate,
we have plans to fix this and allow oAuth authentication without privative libraries.
To login to Gmail / G suite you'll often need an app password, for example when two factor authentication is enabled.
See here for instructions: [https://support.google.com/accounts/answer/185833](https://support.google.com/accounts/answer/185833).
If this doesn't work, see here for more solutions: [https://support.google.com/mail/accounts/answer/78754](https://support.google.com/mail/accounts/answer/78754)
As a temporary solution you need to allow IMAP authentication or how Google says "less secure apps".
See here for instructions: [https://support.google.com/accounts/answer/6010255](https://support.google.com/accounts/answer/6010255)
#### Why are messages in the outbox not moved to the sent folder?


Loading…
Cancel
Save