Compare commits
8
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fe1c590ca | ||
|
|
0231051138 | ||
|
|
4e88587b13 | ||
|
|
41cfeb43fc | ||
|
|
72040b54ae | ||
|
|
ab2b0ce34c | ||
|
|
ce32502eaa | ||
|
|
81812eba1b |
No files matched your search
+3
-1
@@ -61,7 +61,7 @@ android {
|
||||
lint {
|
||||
abortOnError false
|
||||
checkReleaseBuilds false
|
||||
}
|
||||
dependencies }
|
||||
namespace 'com.jens.automation2'
|
||||
buildToolsVersion '36.0.0'
|
||||
}
|
||||
@@ -77,6 +77,8 @@ dependencies {
|
||||
implementation 'com.linkedin.dexmaker:dexmaker:2.28.6'
|
||||
implementation 'org.apache.commons:commons-lang3:3.20.0'
|
||||
|
||||
implementation 'com.sun.mail:android-mail:1.6.4'
|
||||
|
||||
//implementation "androidx.security:security-crypto:1.0.0"
|
||||
//implementation "androidx.security:security-identity-credential:1.0.0-alpha02"
|
||||
implementation 'androidx.appcompat:appcompat:1.4.2'
|
||||
|
||||
@@ -240,6 +240,7 @@
|
||||
<activity android:name=".ActivityManageTriggerCalendar" />
|
||||
<activity android:name=".ActivityManageTriggerProximity" />
|
||||
<activity android:name=".ActivityManageActionSetSystemSetting" />
|
||||
<activity android:name=".ActivityManageActionSendEmail" />
|
||||
|
||||
<service
|
||||
android:name=".receivers.NotificationListener"
|
||||
|
||||
@@ -238,6 +238,7 @@
|
||||
<activity android:name=".ActivityManageTriggerCalendar" />
|
||||
<activity android:name=".ActivityManageTriggerProximity" />
|
||||
<activity android:name=".ActivityManageActionSetSystemSetting" />
|
||||
<activity android:name=".ActivityManageActionSendEmail" />
|
||||
|
||||
<service
|
||||
android:name=".receivers.NotificationListener"
|
||||
|
||||
@@ -60,7 +60,9 @@
|
||||
<uses-permission android:name="android.permission.ACCESS_SUPERUSER" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS"/>
|
||||
<!--
|
||||
Removed due to latest threat mail from Google:
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS"/>-->
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||
<uses-permission android:name="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE"/>
|
||||
<uses-permission android:name="com.wireguard.android.permission.CONTROL_TUNNELS"/>
|
||||
@@ -227,6 +229,7 @@
|
||||
<activity android:name=".ActivityManageTriggerCalendar" />
|
||||
<activity android:name=".ActivityManageTriggerProximity" />
|
||||
<activity android:name=".ActivityManageActionSetSystemSetting" />
|
||||
<activity android:name=".ActivityManageActionSendEmail" />
|
||||
|
||||
<service
|
||||
android:name=".receivers.NotificationListener"
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
@@ -8,10 +9,8 @@ import android.widget.Toast;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
@@ -60,7 +59,9 @@ public class Action
|
||||
setLocationService,
|
||||
sendTextMessage,
|
||||
takeScreenshot,
|
||||
setSystemSetting;
|
||||
setSystemSetting,
|
||||
sendEmail,
|
||||
stopService;
|
||||
|
||||
public String getFullName(Context context)
|
||||
{
|
||||
@@ -134,6 +135,10 @@ public class Action
|
||||
return context.getResources().getString(R.string.setLocationServiceCapital);
|
||||
case setSystemSetting:
|
||||
return context.getResources().getString(R.string.setSystemSettingCapital);
|
||||
case sendEmail:
|
||||
return context.getResources().getString(R.string.sendEmail);
|
||||
case stopService:
|
||||
return context.getResources().getString(R.string.stopService);
|
||||
default:
|
||||
return "Unknown";
|
||||
}
|
||||
@@ -323,6 +328,9 @@ public class Action
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case stopService:
|
||||
returnString.append(Miscellaneous.getAnyContext().getResources().getString(R.string.stopService));
|
||||
break;
|
||||
default:
|
||||
returnString.append(action.toString());
|
||||
}
|
||||
@@ -643,6 +651,12 @@ public class Action
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1)
|
||||
Actions.setSystemSetting(this.getParameter2(), AutomationService.getInstance());
|
||||
break;
|
||||
case sendEmail:
|
||||
Actions.sendEmailFromAction(this);
|
||||
break;
|
||||
case stopService:
|
||||
Intent myServiceIntent = new Intent(Miscellaneous.getAnyContext(), AutomationService.class);
|
||||
Miscellaneous.getAnyContext().stopService(myServiceIntent);
|
||||
default:
|
||||
Miscellaneous.logEvent("w", "Action", context.getResources().getString(R.string.unknownActionSpecified), 3);
|
||||
break;
|
||||
|
||||
@@ -65,6 +65,7 @@ import java.lang.reflect.Method;
|
||||
import java.net.InetAddress;
|
||||
import java.net.NetworkInterface;
|
||||
import java.security.KeyStore;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
@@ -75,6 +76,7 @@ import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.net.ssl.SSLContext;
|
||||
|
||||
import eu.chainfire.libsuperuser.Shell;
|
||||
@@ -2675,4 +2677,24 @@ public class Actions
|
||||
android.provider.Settings.Secure.putString(context.getContentResolver(), android.provider.Settings.Secure.LOCATION_MODE, String.valueOf(desiredState));
|
||||
}
|
||||
|
||||
public static boolean sendEmailFromAction(Action action)
|
||||
{
|
||||
try
|
||||
{
|
||||
String[] components = action.getParameter2().split(Action.actionParameter2Split, -1);
|
||||
EmailService es = new EmailService(Settings.smtpServerHostname, Integer.parseInt(Settings.smtpServerPort), Settings.smtpServerUseTls);
|
||||
List<InternetAddress> toAddressList = new ArrayList<>();
|
||||
toAddressList.add(new InternetAddress(components[0]));
|
||||
|
||||
EmailService.Email em = new EmailService.Email(new EmailService.UserPassAuthenticator(Settings.smtpUsername, Settings.smtpPassword), new InternetAddress(Settings.smtpFromAddress), toAddressList, components[1], components[2]);
|
||||
es.send(em);
|
||||
Miscellaneous.logEvent("i", "sendEmail()", "Email sent.", 1);
|
||||
return true;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Miscellaneous.logEvent("e", "sendEmail()", "Email could not be sent: " + Log.getStackTraceString(e), 1);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,89 @@
|
||||
package com.jens.automation2;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.Button;
|
||||
import android.widget.CompoundButton;
|
||||
import android.widget.EditText;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
import com.jens.automation2.Action.Action_Enum;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
|
||||
public class ActivityManageActionSendEmail extends Activity
|
||||
{
|
||||
Button bSaveSendEmail;
|
||||
TextView tvEmailServerConfigurationNotice;
|
||||
EditText etEmailRecipient, etEmailSubject, etEmailText;
|
||||
|
||||
public static boolean edit = false;
|
||||
public static Action resultingAction = null;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
Miscellaneous.setDisplayLanguage(this);
|
||||
Miscellaneous.setUiTheme(this);
|
||||
this.setContentView(R.layout.activity_manage_action_send_email);
|
||||
|
||||
tvEmailServerConfigurationNotice = (TextView)findViewById(R.id.tvEmailServerConfigurationNotice);
|
||||
etEmailRecipient = (EditText)findViewById(R.id.etEmailRecipient);
|
||||
etEmailSubject = (EditText)findViewById(R.id.etEmailSubject);
|
||||
etEmailText = (EditText)findViewById(R.id.etEmailText);
|
||||
bSaveSendEmail = (Button)findViewById(R.id.bSaveSendEmail);
|
||||
|
||||
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||
{
|
||||
String[] components = getIntent().getStringExtra(ActivityManageRule.intentNameActionParameter2).split(Action.actionParameter2Split, -1);
|
||||
etEmailRecipient.setText(components[0]);
|
||||
etEmailSubject.setText(components[1]);
|
||||
etEmailText.setText(components[2]);
|
||||
}
|
||||
|
||||
if(Settings.smtpServerHostname.isEmpty())
|
||||
tvEmailServerConfigurationNotice.setVisibility(View.VISIBLE);
|
||||
else
|
||||
tvEmailServerConfigurationNotice.setVisibility(View.GONE);
|
||||
|
||||
bSaveSendEmail.setOnClickListener(new OnClickListener()
|
||||
{
|
||||
@Override
|
||||
public void onClick(View v)
|
||||
{
|
||||
if(etEmailRecipient.getText().toString().length() > 0 && etEmailSubject.getText().toString().length() > 0 && etEmailText.getText().toString().length() > 0)
|
||||
{
|
||||
if (resultingAction == null)
|
||||
resultingAction = new Action();
|
||||
|
||||
String responseString = etEmailRecipient.getText().toString() + Action.actionParameter2Split + etEmailSubject.getText().toString() + Action.actionParameter2Split + etEmailText.getText().toString();
|
||||
|
||||
Intent answer = new Intent();
|
||||
|
||||
answer.putExtra(ActivityManageRule.intentNameActionParameter2, responseString);
|
||||
|
||||
setResult(RESULT_OK, answer);
|
||||
ActivityManageActionSendEmail.this.finish();
|
||||
}
|
||||
else
|
||||
Toast.makeText(getBaseContext(), getResources().getString(R.string.enterAllValues), Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,9 @@ import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.widget.AdapterView;
|
||||
@@ -27,9 +30,13 @@ import androidx.annotation.NonNull;
|
||||
import com.jens.automation2.Action.Action_Enum;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.w3c.dom.Text;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ActivityManageActionTriggerUrl extends Activity
|
||||
{
|
||||
@@ -39,7 +46,7 @@ public class ActivityManageActionTriggerUrl extends Activity
|
||||
CheckBox chkTriggerUrlUseAuthentication;
|
||||
RadioButton rbTriggerUrlMethodGet, rbTriggerUrlMethodPost;
|
||||
TableLayout tlTriggerUrlAuthentication;
|
||||
TextView tvHttpParameterExplanation;
|
||||
TextView tvHttpParameterExplanation, tvUrlValidator;
|
||||
ArrayAdapter<String> httpParametersAdapter;
|
||||
|
||||
private ArrayList<String> httpParamsList = new ArrayList<>();
|
||||
@@ -70,6 +77,7 @@ public class ActivityManageActionTriggerUrl extends Activity
|
||||
etParameterValue = (EditText)findViewById(R.id.etParameterValue);
|
||||
bAddHttpParam = (Button)findViewById(R.id.bAddHttpParam);
|
||||
tvHttpParameterExplanation = (TextView)findViewById(R.id.tvHttpParameterExplanation);
|
||||
tvUrlValidator = (TextView)findViewById(R.id.tvUrlValidator);
|
||||
|
||||
etParameterName.setEnabled(false);
|
||||
etParameterValue.setEnabled(false);
|
||||
@@ -173,6 +181,33 @@ public class ActivityManageActionTriggerUrl extends Activity
|
||||
});
|
||||
updateListView();
|
||||
|
||||
etTriggerUrl.addTextChangedListener(new TextWatcher()
|
||||
{
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable)
|
||||
{
|
||||
if(etTriggerUrl.getText() != null && etTriggerUrl.getText().length() > 0)
|
||||
{
|
||||
if(Miscellaneous.isValidUrl(etTriggerUrl.getText().toString()))
|
||||
tvUrlValidator.setText("");
|
||||
else
|
||||
tvUrlValidator.setText(getResources().getString(R.string.enter_valid_url));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2)
|
||||
{
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
if(getIntent().hasExtra(ActivityManageRule.intentNameActionParameter2))
|
||||
{
|
||||
// username,password,URL,etc.
|
||||
|
||||
@@ -151,6 +151,8 @@ public class ActivityManageRule extends Activity
|
||||
final static int requestCodeTriggerProximityEdit = 838;
|
||||
final static int requestCodeActionSetSystemSettingAdd = 839;
|
||||
final static int requestCodeActionSetSystemSettingEdit = 840;
|
||||
final static int requestCodeActionSendEmailAdd = 841;
|
||||
final static int requestCodeActionSendEmailEdit = 842;
|
||||
|
||||
public static ActivityManageRule getInstance()
|
||||
{
|
||||
@@ -2263,6 +2265,32 @@ public class ActivityManageRule extends Activity
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionSendEmailAdd)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
newAction.setParentRule(ruleToEdit);
|
||||
// newAction.setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||
newAction.setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
ruleToEdit.getActionSet().add(newAction);
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
else if(requestCode == requestCodeActionSendEmailEdit)
|
||||
{
|
||||
if(resultCode == RESULT_OK)
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParentRule(ruleToEdit);
|
||||
// ruleToEdit.getActionSet().get(editIndex).setParameter1(data.getBooleanExtra(intentNameActionParameter1, false));
|
||||
|
||||
if(data.hasExtra(intentNameActionParameter2))
|
||||
{
|
||||
ruleToEdit.getActionSet().get(editIndex).setParameter2(data.getStringExtra(intentNameActionParameter2));
|
||||
}
|
||||
|
||||
this.refreshActionList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected AlertDialog getActionTypeDialog()
|
||||
@@ -2343,14 +2371,17 @@ public class ActivityManageRule extends Activity
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.variable));
|
||||
else if(types[i].toString().equals(Action_Enum.setLocationService.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.compass_small));
|
||||
else if(types[i].toString().equals(Action_Enum.sendEmail.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.email));
|
||||
else if(types[i].toString().equals(Action_Enum.takeScreenshot.toString()))
|
||||
{
|
||||
if(ActivityPermissions.isServiceAvailable(Miscellaneous.getAnyContext(), "MyAccessibilityService"))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.copier));
|
||||
}
|
||||
else if(types[i].toString().equals(Action_Enum.setSystemSetting.toString()))
|
||||
{ items.add(new Item(typesLong[i].toString(), R.drawable.gears_small));
|
||||
}
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.gears_small));
|
||||
else if(types[i].toString().equals(Action_Enum.stopService.toString()))
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.stop_service));
|
||||
else
|
||||
items.add(new Item(typesLong[i].toString(), R.drawable.placeholder));
|
||||
}
|
||||
@@ -2595,6 +2626,18 @@ public class ActivityManageRule extends Activity
|
||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionSetSystemSetting.class);
|
||||
startActivityForResult(intent, requestCodeActionSetSystemSettingAdd);
|
||||
}
|
||||
else if(actionTypes[which].toString().equals(Action_Enum.sendEmail.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.sendEmail);
|
||||
Intent intent = new Intent(ActivityManageRule.this, ActivityManageActionSendEmail.class);
|
||||
startActivityForResult(intent, requestCodeActionSendEmailAdd);
|
||||
}
|
||||
else if(actionTypes[which].toString().equals(Action_Enum.stopService.toString()))
|
||||
{
|
||||
newAction.setAction(Action_Enum.stopService);
|
||||
ruleToEdit.getActionSet().add(newAction);
|
||||
refreshActionList();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
@@ -102,6 +102,12 @@ public class ActivityManageTriggerPhoneCall extends Activity
|
||||
@Override
|
||||
public void onClick(View view)
|
||||
{
|
||||
if(BuildConfig.FLAVOR.equals(AutomationService.flavor_name_googleplay))
|
||||
{
|
||||
Miscellaneous.messageBox(getResources().getString(R.string.info), getResources().getString(R.string.featureNotInGooglePlayVersion), ActivityManageTriggerPhoneCall.this).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !ActivityPermissions.havePermission("android.permission.READ_CONTACTS", ActivityManageTriggerPhoneCall.this))
|
||||
{
|
||||
requestPermissions("android.permission.READ_CONTACTS");
|
||||
|
||||
@@ -7,20 +7,19 @@ import android.annotation.SuppressLint;
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManager.RunningServiceInfo;
|
||||
import android.app.Notification;
|
||||
import android.app.Notification.Builder;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.ServiceInfo;
|
||||
import android.media.AudioManager;
|
||||
import android.os.Binder;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Environment;
|
||||
import android.os.IBinder;
|
||||
import android.os.StrictMode;
|
||||
import android.speech.tts.TextToSpeech;
|
||||
import android.speech.tts.TextToSpeech.OnInitListener;
|
||||
import android.util.Log;
|
||||
@@ -36,11 +35,17 @@ import com.jens.automation2.receivers.DateTimeListener;
|
||||
import com.jens.automation2.receivers.PackageReplacedReceiver;
|
||||
import com.jens.automation2.receivers.PhoneStatusListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.AddressException;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
|
||||
@SuppressLint("NewApi")
|
||||
public class AutomationService extends Service implements OnInitListener
|
||||
{
|
||||
@@ -469,7 +474,7 @@ public class AutomationService extends Service implements OnInitListener
|
||||
if(displayNotification)
|
||||
{
|
||||
Intent intent = new Intent(AutomationService.this, ActivityPermissions.class);
|
||||
PendingIntent pi = PendingIntent.getActivity(AutomationService.this, 0, intent, 0);
|
||||
PendingIntent pi = PendingIntent.getActivity(AutomationService.this, 0, intent, FLAG_IMMUTABLE);
|
||||
|
||||
Miscellaneous.logEvent("w", "Features disabled", "Features disabled because of rule " + rule, 5);
|
||||
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
package com.jens.automation2;
|
||||
import java.util.Calendar;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.mail.Address;
|
||||
import javax.mail.Authenticator;
|
||||
import javax.mail.Message;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.PasswordAuthentication;
|
||||
import javax.mail.Session;
|
||||
import javax.mail.Transport;
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.mail.internet.MimeBodyPart;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import javax.mail.internet.MimeMultipart;
|
||||
|
||||
public class EmailService
|
||||
{
|
||||
private final String server;
|
||||
private final int port;
|
||||
private final boolean useTls;
|
||||
|
||||
public static final String CLIENT_NAME = "Android StackOverflow programmatic email";
|
||||
|
||||
public EmailService(String server, int port, boolean useTls)
|
||||
{
|
||||
this.server = server;
|
||||
this.port = port;
|
||||
this.useTls = useTls;
|
||||
}
|
||||
|
||||
public static class Email
|
||||
{
|
||||
private Authenticator auth;
|
||||
private final List<InternetAddress> toList;
|
||||
private final Address from;
|
||||
private final String subject;
|
||||
private final String body;
|
||||
|
||||
public Email(Authenticator auth, Address from, List<InternetAddress> toList, String subject, String body)
|
||||
{
|
||||
this.auth = auth;
|
||||
this.from = from;
|
||||
this.toList = toList;
|
||||
this.subject = subject;
|
||||
this.body = body;
|
||||
}
|
||||
|
||||
public Authenticator getAuth()
|
||||
{
|
||||
return auth;
|
||||
}
|
||||
|
||||
public List<InternetAddress> getToList()
|
||||
{
|
||||
return toList;
|
||||
}
|
||||
|
||||
public Address getFrom()
|
||||
{
|
||||
return from;
|
||||
}
|
||||
|
||||
public String getSubject()
|
||||
{
|
||||
return subject;
|
||||
}
|
||||
|
||||
public String getBody()
|
||||
{
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
public static class UserPassAuthenticator extends Authenticator
|
||||
{
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
||||
public UserPassAuthenticator(String username, String password)
|
||||
{
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PasswordAuthentication getPasswordAuthentication()
|
||||
{
|
||||
return new PasswordAuthentication(username, password);
|
||||
}
|
||||
}
|
||||
|
||||
public void send(Email email) throws MessagingException
|
||||
{
|
||||
Properties props = new Properties();
|
||||
if(((UserPassAuthenticator)email.getAuth()).getPasswordAuthentication().getUserName().isEmpty())
|
||||
{
|
||||
props.put("mail.smtp.auth", "false");
|
||||
email.auth = null;
|
||||
}
|
||||
else
|
||||
props.put("mail.smtp.auth", "true");
|
||||
|
||||
props.put("mail.user", email.getFrom().toString());
|
||||
props.put("mail.smtp.host", server);
|
||||
props.put("mail.smtp.port", String.valueOf(port));
|
||||
|
||||
if(useTls)
|
||||
{
|
||||
props.put("mail.smtp.starttls.enable", "true");
|
||||
props.put("mail.smtp.ssl.trust", server);
|
||||
}
|
||||
else
|
||||
props.put("mail.smtp.starttls.enable", "false");
|
||||
|
||||
props.put("mail.mime.charset", "UTF-8");
|
||||
|
||||
Session session = Session.getDefaultInstance(props, email.getAuth());
|
||||
MimeMessage msg = new MimeMessage(session);
|
||||
|
||||
msg.setFrom(email.getFrom());
|
||||
msg.setSentDate(Calendar.getInstance().getTime());
|
||||
Address[] toArray = new Address[]{email.getFrom()};
|
||||
msg.setRecipients(Message.RecipientType.TO, toArray);
|
||||
|
||||
msg.setReplyTo(new Address[]{email.getFrom()});
|
||||
|
||||
msg.addHeader("X-Mailer", CLIENT_NAME);
|
||||
msg.addHeader("Precedence", "bulk");
|
||||
msg.setSubject(email.getSubject());
|
||||
|
||||
MimeMultipart multipart = new MimeMultipart();
|
||||
MimeBodyPart bodyPart = new MimeBodyPart();
|
||||
bodyPart.setText(email.getBody(), "iso-8859-1");
|
||||
multipart.addBodyPart(bodyPart);
|
||||
|
||||
msg.setContent(multipart);
|
||||
Transport.send(msg);
|
||||
}
|
||||
}
|
||||
@@ -105,10 +105,13 @@ import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Scanner;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
import java.util.zip.ZipOutputStream;
|
||||
|
||||
import javax.mail.internet.InternetAddress;
|
||||
import javax.net.ssl.HostnameVerifier;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
@@ -133,6 +136,9 @@ public class Miscellaneous extends Service
|
||||
protected final static String httpMainData = "httpMainData";
|
||||
protected final static String doNoEncodingString = "NoEncoding";
|
||||
protected final static String httpEncoding = "UTF-8";
|
||||
protected final static String URL_REGEX = "^(https?):\\/\\/([a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*)(:[0-9]{1,5})?([\\/\\?#].*)?$";
|
||||
// protected final static String URL_REGEX = "^(https?|ftp):\\/\\/([a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*)(:[0-9]{1,5})?([\\/\\?#].*)?$";
|
||||
protected final static Pattern URL_PATTERN = Pattern.compile(URL_REGEX, Pattern.CASE_INSENSITIVE);
|
||||
public static Context startupContext;
|
||||
|
||||
public static final String lineSeparator = System.getProperty("line.separator");
|
||||
@@ -2072,7 +2078,7 @@ public class Miscellaneous extends Service
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
Miscellaneous.logEvent("e", "unzip()", Log.getStackTraceString(e), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2109,7 +2115,7 @@ public class Miscellaneous extends Service
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println(e);
|
||||
Miscellaneous.logEvent("e", "unzip()", Log.getStackTraceString(e), 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2122,9 +2128,8 @@ public class Miscellaneous extends Service
|
||||
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{targetAddress});
|
||||
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, subject);
|
||||
if (fileAttachment != null)
|
||||
{
|
||||
emailIntent.putExtra(Intent.EXTRA_STREAM, fileAttachment);
|
||||
}
|
||||
|
||||
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
|
||||
context.startActivity(Intent.createChooser(emailIntent, "Sending email..."));
|
||||
}
|
||||
@@ -2428,4 +2433,13 @@ public class Miscellaneous extends Service
|
||||
StackTraceElement callingFrame = Thread.currentThread().getStackTrace()[4];
|
||||
return callingFrame.getMethodName();
|
||||
}
|
||||
|
||||
public static boolean isValidUrl(String input)
|
||||
{
|
||||
if (input == null || input.length() == 0)
|
||||
return false;
|
||||
|
||||
Matcher matcher = URL_PATTERN.matcher(input);
|
||||
return matcher.matches(); // Returns true if the entire string matches
|
||||
}
|
||||
}
|
||||
@@ -73,6 +73,14 @@ public class Settings implements SharedPreferences
|
||||
public static long musicCheckFrequency;
|
||||
public static String displayLanguage;
|
||||
|
||||
public static String smtpServerHostname;
|
||||
public static String smtpServerPort;
|
||||
public static boolean smtpServerUseTls;
|
||||
public static String smtpFromAddress;
|
||||
public static String smtpToAddress;
|
||||
public static String smtpUsername;
|
||||
public static String smtpPassword;
|
||||
|
||||
public static boolean lockSoundChanges;
|
||||
public static boolean noticeAndroid9MicrophoneShown;
|
||||
public static boolean noticeAndroid10WifiShown;
|
||||
@@ -146,6 +154,14 @@ public class Settings implements SharedPreferences
|
||||
public static final long default_musicCheckFrequency = 2500;
|
||||
public static final String default_displayLanguage = "systemDefaultLanguage";
|
||||
|
||||
public static final String default_smtpServerHostname = "";
|
||||
public static final String default_smtpServerPort = "587";
|
||||
public static final boolean default_smtpServerUseTls = false;
|
||||
public static final String default_smtpFromAddress = "";
|
||||
public static final String default_smtpToAddress = "";
|
||||
public static final String default_smtpUsername = "";
|
||||
public static final String default_smtpPassword = "";
|
||||
|
||||
@Override
|
||||
public boolean contains(String arg0)
|
||||
{
|
||||
@@ -273,6 +289,14 @@ public class Settings implements SharedPreferences
|
||||
musicCheckFrequency = Long.parseLong(prefs.getString("musicCheckFrequency", String.valueOf(default_musicCheckFrequency)));
|
||||
displayLanguage = prefs.getString("displayLanguage", default_displayLanguage);
|
||||
|
||||
smtpServerHostname = prefs.getString("smtpServerHostname", default_smtpServerHostname);
|
||||
smtpServerPort = prefs.getString("smtpServerPort", default_smtpServerPort);
|
||||
smtpServerUseTls = prefs.getBoolean("smtpServerUseTls", default_smtpServerUseTls);
|
||||
smtpFromAddress = prefs.getString("smtpFromAddress", default_smtpFromAddress);
|
||||
smtpToAddress = prefs.getString("smtpToAddress", default_smtpToAddress);
|
||||
smtpUsername = prefs.getString("smtpUsername", default_smtpUsername);
|
||||
smtpPassword = prefs.getString("smtpPassword", default_smtpPassword);
|
||||
|
||||
if(Settings.musicCheckFrequency == 0)
|
||||
Settings.musicCheckFrequency = Settings.default_musicCheckFrequency;
|
||||
|
||||
@@ -490,6 +514,27 @@ public class Settings implements SharedPreferences
|
||||
if(!prefs.contains("displayLanguage") || force)
|
||||
editor.putString("displayLanguage", default_displayLanguage);
|
||||
|
||||
if(!prefs.contains("smtpServerHostname") || force)
|
||||
editor.putString("smtpServerHostname", default_smtpServerHostname);
|
||||
|
||||
if(!prefs.contains("smtpServerPort") || force)
|
||||
editor.putString("smtpServerPort", default_smtpServerPort);
|
||||
|
||||
if(!prefs.contains("smtpServerUseTls") || force)
|
||||
editor.putBoolean("smtpServerUseTls", default_smtpServerUseTls);
|
||||
|
||||
if(!prefs.contains("smtpFromAddress") || force)
|
||||
editor.putString("smtpFromAddress", default_smtpFromAddress);
|
||||
|
||||
if(!prefs.contains("smtpToAddress") || force)
|
||||
editor.putString("smtpToAddress", default_smtpToAddress);
|
||||
|
||||
if(!prefs.contains("smtpUsername") || force)
|
||||
editor.putString("smtpUsername", default_smtpUsername);
|
||||
|
||||
if(!prefs.contains("smtpPassword") || force)
|
||||
editor.putString("smtpPassword", default_smtpPassword);
|
||||
|
||||
if(!prefs.contains("lockSoundChanges") || force)
|
||||
editor.putBoolean("lockSoundChanges", default_lockSoundChanges);
|
||||
|
||||
@@ -580,6 +625,14 @@ public class Settings implements SharedPreferences
|
||||
|
||||
editor.putString("displayLanguage", displayLanguage);
|
||||
|
||||
editor.putString("smtpServerHostname", smtpServerHostname);
|
||||
editor.putString("smtpServerPort", smtpServerPort);
|
||||
editor.putBoolean("smtpServerUseTls", smtpServerUseTls);
|
||||
editor.putString("smtpFromAddress", smtpFromAddress);
|
||||
editor.putString("smtpToAddress", smtpToAddress);
|
||||
editor.putString("smtpUsername", smtpUsername);
|
||||
editor.putString("smtpPassword", smtpPassword);
|
||||
|
||||
editor.putBoolean("lockSoundChanges", lockSoundChanges);
|
||||
editor.putBoolean("noticeAndroid9MicrophoneShown", noticeAndroid9MicrophoneShown);
|
||||
editor.putBoolean("noticeAndroid10WifiShown", noticeAndroid10WifiShown);
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.9 KiB |
@@ -0,0 +1,91 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_margin="@dimen/default_margin" >
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textSize="25dp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginBottom="@dimen/default_margin"
|
||||
android:text="@string/sendEmail" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvEmailServerConfigurationNotice"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/emailConfigurationNotice"
|
||||
android:textColor="#ea131b"
|
||||
android:layout_marginBottom="@dimen/default_margin" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/emailRecipient" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etEmailRecipient"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="textEmailAddress" >
|
||||
|
||||
<requestFocus />
|
||||
</EditText>
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/emailSubject" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etEmailSubject"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="text" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/textToSend" />
|
||||
|
||||
<EditText
|
||||
android:id="@+id/etEmailText"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:ems="10"
|
||||
android:inputType="text|textMultiLine" >
|
||||
</EditText>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvLegend"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/urlLegend" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/attachment" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/bSaveSendEmail"
|
||||
android:layout_marginTop="15dp"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/save" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</ScrollView>
|
||||
@@ -35,6 +35,12 @@
|
||||
|
||||
</EditText>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvUrlValidator"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/red" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
||||
@@ -307,5 +307,52 @@
|
||||
android:inputType="number" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
<PreferenceCategory
|
||||
android:summary="@string/settingsCategorySendEmails"
|
||||
android:title="@string/settingsCategorySendEmails">
|
||||
|
||||
<EditTextPreference
|
||||
android:key="smtpServerHostname"
|
||||
android:summary="@string/smtpServerHostnameSummary"
|
||||
android:title="@string/smtpServerHostnameTitle"
|
||||
android:inputType="text" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="smtpServerPort"
|
||||
android:summary="@string/smtpServerPortSummary"
|
||||
android:title="@string/smtpServerPortTitle"
|
||||
android:inputType="number" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:key="smtpServerUseTls"
|
||||
android:summary="@string/smtpServerUseTlsSummary"
|
||||
android:title="@string/smtpServerUseTlsTitle" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="smtpFromAddress"
|
||||
android:summary="@string/smtpFromAddressSummary"
|
||||
android:title="@string/smtpFromAddressTitle"
|
||||
android:inputType="textEmailAddress" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="smtpToAddress"
|
||||
android:summary="@string/smtpToAddressSummary"
|
||||
android:title="@string/smtpToAddressTitle"
|
||||
android:inputType="textEmailAddress" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="smtpUsername"
|
||||
android:summary="@string/smtpUsernameSummary"
|
||||
android:title="@string/smtpUsernameTitle"
|
||||
android:inputType="text" />
|
||||
|
||||
<EditTextPreference
|
||||
android:key="smtpPassword"
|
||||
android:summary="@string/smtpPasswordSummary"
|
||||
android:title="@string/smtpPasswordTitle"
|
||||
android:inputType="textPassword" />
|
||||
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -887,5 +887,5 @@
|
||||
<string name="enterAvalue">Geben Sie einen Wert ein.</string>
|
||||
<string name="setSystemSettingCapital">Systemeinstellung setzen</string>
|
||||
<string name="examplesWriteSecureSettings">Ich führe keine Liste möglicher Einstellungen. Bitte finden Sie diese Einstellungen selbst. Siehe <a href="https://developer.android.com/reference/android/provider/Settings.Secure">hier</a> für einige (unvollständige) Beispiele.</string>
|
||||
<string name="httpParametersExplanation">Beginnt ein Parametername mit %1$s, während die Methode POST ist, wird er nicht wie die anderen Parameter (mit Schlüssel=Wert) übertragen, sondern als Hauptdaten übertragen. Wenn der Parameter mit 2 % endet, wird keine Codierung durchgeführt.</string>
|
||||
<string name="httpParametersExplanation">Beginnt ein Parametername mit %1$s, während die Methode POST ist, wird er nicht wie die anderen Parameter (mit Schlüssel=Wert) übertragen, sondern als Hauptdaten übertragen. Wenn der Parameter mit %2$s endet, wird keine Codierung durchgeführt.</string>
|
||||
</resources>
|
||||
@@ -698,7 +698,7 @@
|
||||
<string name="bottom">Bottom</string>
|
||||
<string name="tabsPlacement">Position of tab bar</string>
|
||||
<string name="tabsPlacementSummary">Choose where the tabs bar should be placed.</string>
|
||||
<string name="wifiApi30">Because Google screwed up yet another part of Android, starting with API 30 only the currently visible wifis can be displayed, not all the ones your device has connected to anymore.</string>
|
||||
<string name="wifiApi30">Because Google screwed up yet another part of Android, starting with API 30 only the currently visible Wi-Fi can be displayed, not all the ones your device has connected to anymore.</string>
|
||||
<string name="silentTriggersDnd">REMARK: The silent mode often triggers Do-Not-Disturb on newer devices. If that happens on your device, I recommend using the normal mode instead and lowering all volumes to zero.</string>
|
||||
<string name="tones">Tones</string>
|
||||
<string name="miscellaneous">Miscellaneous</string>
|
||||
@@ -979,4 +979,27 @@
|
||||
<string name="examplesWriteSecureSettings">I do not keep a list of possible settings. Please find those settings on your own. See <a href="https://developer.android.com/reference/android/provider/Settings.Secure">here</a> for some (incomplete) examples.</string>
|
||||
<string name="httpParametersExplanation">If any parameter name starts with %1$s while method is POST, it will not be transmitted like the other parameters (with key=value), but transferred as main data. If the parameter ends with %2$s, no encoding will be performed.</string>
|
||||
<string name="target">Target</string>
|
||||
<string name="enter_valid_url">Enter a valid URL.</string>
|
||||
<string name="settingsCategorySendEmails">Email server settings</string>
|
||||
<string name="smtpServerHostnameTitle">Hostname</string>
|
||||
<string name="smtpServerHostnameSummary">SMTP server hostname</string>
|
||||
<string name="smtpServerPortTitle">Port</string>
|
||||
<string name="smtpServerPortSummary">SMTP server port</string>
|
||||
<string name="smtpServerUseTlsTitle">Use TLS</string>
|
||||
<string name="smtpServerUseTlsSummary">Use TLS for connection to SMTP server</string>
|
||||
<string name="smtpFromAddressTitle">From address</string>
|
||||
<string name="smtpFromAddressSummary">Sender address emails (from)</string>
|
||||
<string name="smtpToAddressTitle">Recipient address</string>
|
||||
<string name="smtpToAddressSummary">Recipient address for emails (to)</string>
|
||||
<string name="smtpUsernameTitle">Username</string>
|
||||
<string name="smtpUsernameSummary">Leave empty for no authentication</string>
|
||||
<string name="smtpPasswordTitle">Password</string>
|
||||
<string name="smtpPasswordSummary">If username is empty, no authentication is used.</string>
|
||||
<string name="sendEmail">Send email</string>
|
||||
<string name="emailTo">Recipient</string>
|
||||
<string name="emailRecipient">Recipient</string>
|
||||
<string name="emailSubject">Subject</string>
|
||||
<string name="enterAllValues">Enter all values.</string>
|
||||
<string name="emailConfigurationNotice">Remember to configure an SMTP server in settings.</string>
|
||||
<string name="stopService">Stop service</string>
|
||||
</resources>
|
||||
@@ -1 +1,6 @@
|
||||
* Added: Triggers and actions can now be cloned
|
||||
* Added: Triggers and actions can now be cloned
|
||||
* Added: URL checker for triggerUrl action
|
||||
* Added: Send emails as action
|
||||
* Added: Stop service as action
|
||||
* Fixed: Crash when starting to add/edit a triggerURL action while the app or the system are set to the German language
|
||||
* Fixed: Crash when starting service in Google Play version
|
||||
Reference in new issue
Block a user