mirror of
https://github.com/pppscn/SmsForwarder
synced 2025-08-03 17:37:40 +08:00
新增:邮件主题支持自定义模板
新增:{{当前应用版本号}} 来获取 SmsForwarder 当前版本名
This commit is contained in:
parent
fb31d64298
commit
dbab4718e0
@ -353,21 +353,25 @@ public class SenderActivity extends AppCompatActivity {
|
||||
|
||||
final EditText editTextEmailName = view1.findViewById(R.id.editTextEmailName);
|
||||
if (senderModel != null) editTextEmailName.setText(senderModel.getName());
|
||||
final EditText editTextEmailHost = view1.findViewById(R.id.editTextEmailHost);
|
||||
if (emailSettingVo != null) editTextEmailHost.setText(emailSettingVo.getHost());
|
||||
final EditText editTextEmailPort = view1.findViewById(R.id.editTextEmailPort);
|
||||
if (emailSettingVo != null) editTextEmailPort.setText(emailSettingVo.getPort());
|
||||
|
||||
final EditText editTextEmailHost = view1.findViewById(R.id.editTextEmailHost);
|
||||
final EditText editTextEmailPort = view1.findViewById(R.id.editTextEmailPort);
|
||||
@SuppressLint("UseSwitchCompatOrMaterialCode") final Switch switchEmailSSl = view1.findViewById(R.id.switchEmailSSl);
|
||||
if (emailSettingVo != null) switchEmailSSl.setChecked(emailSettingVo.getSsl());
|
||||
final EditText editTextEmailFromAdd = view1.findViewById(R.id.editTextEmailFromAdd);
|
||||
if (emailSettingVo != null) editTextEmailFromAdd.setText(emailSettingVo.getFromEmail());
|
||||
final EditText editTextEmailNickname = view1.findViewById(R.id.editTextEmailNickname);
|
||||
if (emailSettingVo != null) editTextEmailNickname.setText(emailSettingVo.getNickname());
|
||||
final EditText editTextEmailPsw = view1.findViewById(R.id.editTextEmailPsw);
|
||||
if (emailSettingVo != null) editTextEmailPsw.setText(emailSettingVo.getPwd());
|
||||
final EditText editTextEmailToAdd = view1.findViewById(R.id.editTextEmailToAdd);
|
||||
if (emailSettingVo != null) editTextEmailToAdd.setText(emailSettingVo.getToEmail());
|
||||
final EditText editTextEmailTitle = view1.findViewById(R.id.editTextEmailTitle);
|
||||
if (emailSettingVo != null) {
|
||||
editTextEmailHost.setText(emailSettingVo.getHost());
|
||||
editTextEmailPort.setText(emailSettingVo.getPort());
|
||||
switchEmailSSl.setChecked(emailSettingVo.getSsl());
|
||||
editTextEmailFromAdd.setText(emailSettingVo.getFromEmail());
|
||||
editTextEmailNickname.setText(emailSettingVo.getNickname());
|
||||
editTextEmailPsw.setText(emailSettingVo.getPwd());
|
||||
editTextEmailToAdd.setText(emailSettingVo.getToEmail());
|
||||
editTextEmailTitle.setText(emailSettingVo.getTitle());
|
||||
}
|
||||
|
||||
Button buttonEmailOk = view1.findViewById(R.id.buttonEmailOk);
|
||||
Button buttonEmailDel = view1.findViewById(R.id.buttonEmailDel);
|
||||
@ -380,7 +384,6 @@ public class SenderActivity extends AppCompatActivity {
|
||||
final AlertDialog show = alertDialog71.show();
|
||||
|
||||
buttonEmailOk.setOnClickListener(view -> {
|
||||
|
||||
if (senderModel == null) {
|
||||
SenderModel newSenderModel = new SenderModel();
|
||||
newSenderModel.setName(editTextEmailName.getText().toString());
|
||||
@ -393,7 +396,8 @@ public class SenderActivity extends AppCompatActivity {
|
||||
editTextEmailFromAdd.getText().toString(),
|
||||
editTextEmailNickname.getText().toString(),
|
||||
editTextEmailPsw.getText().toString(),
|
||||
editTextEmailToAdd.getText().toString()
|
||||
editTextEmailToAdd.getText().toString(),
|
||||
editTextEmailTitle.getText().toString()
|
||||
);
|
||||
newSenderModel.setJsonSetting(JSON.toJSONString(emailSettingVoNew));
|
||||
SenderUtil.addSender(newSenderModel);
|
||||
@ -410,7 +414,8 @@ public class SenderActivity extends AppCompatActivity {
|
||||
editTextEmailFromAdd.getText().toString(),
|
||||
editTextEmailNickname.getText().toString(),
|
||||
editTextEmailPsw.getText().toString(),
|
||||
editTextEmailToAdd.getText().toString()
|
||||
editTextEmailToAdd.getText().toString(),
|
||||
editTextEmailTitle.getText().toString()
|
||||
);
|
||||
senderModel.setJsonSetting(JSON.toJSONString(emailSettingVoNew));
|
||||
SenderUtil.updateSender(senderModel);
|
||||
@ -419,8 +424,6 @@ public class SenderActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
show.dismiss();
|
||||
|
||||
|
||||
});
|
||||
buttonEmailDel.setOnClickListener(view -> {
|
||||
if (senderModel != null) {
|
||||
@ -438,14 +441,15 @@ public class SenderActivity extends AppCompatActivity {
|
||||
String pwd = editTextEmailPsw.getText().toString();
|
||||
String toEmail = editTextEmailToAdd.getText().toString();
|
||||
|
||||
String title = editTextEmailTitle.getText().toString();
|
||||
if (title.isEmpty()) title = "SmsForwarder Title";
|
||||
|
||||
String nickname = editTextEmailNickname.getText().toString();
|
||||
if (nickname.equals("")) {
|
||||
nickname = "SmsForwarder";
|
||||
}
|
||||
if (nickname.isEmpty()) nickname = "SmsForwarder";
|
||||
|
||||
if (!host.isEmpty() && !port.isEmpty() && !fromEmail.isEmpty() && !pwd.isEmpty() && !toEmail.isEmpty()) {
|
||||
try {
|
||||
SenderMailMsg.sendEmail(0, handler, host, port, ssl, fromEmail, nickname, pwd, toEmail, "SmsForwarder Title", R.string.test_content + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
|
||||
SenderMailMsg.sendEmail(0, handler, host, port, ssl, fromEmail, nickname, pwd, toEmail, title, R.string.test_content + (new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())));
|
||||
} catch (Exception e) {
|
||||
Toast.makeText(SenderActivity.this, getString(R.string.failed_to_fwd) + e.getMessage(), Toast.LENGTH_LONG).show();
|
||||
e.printStackTrace();
|
||||
@ -454,6 +458,36 @@ public class SenderActivity extends AppCompatActivity {
|
||||
Toast.makeText(SenderActivity.this, R.string.invalid_email, Toast.LENGTH_LONG).show();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
Button buttonInsertSender = view1.findViewById(R.id.bt_insert_sender);
|
||||
buttonInsertSender.setOnClickListener(view -> {
|
||||
editTextEmailTitle.setFocusable(true);
|
||||
editTextEmailTitle.requestFocus();
|
||||
editTextEmailTitle.append("{{来源号码}}");
|
||||
});
|
||||
|
||||
Button buttonInsertExtra = view1.findViewById(R.id.bt_insert_extra);
|
||||
buttonInsertExtra.setOnClickListener(view -> {
|
||||
editTextEmailTitle.setFocusable(true);
|
||||
editTextEmailTitle.requestFocus();
|
||||
editTextEmailTitle.append("{{卡槽信息}}");
|
||||
});
|
||||
|
||||
Button buttonInsertTime = view1.findViewById(R.id.bt_insert_time);
|
||||
buttonInsertTime.setOnClickListener(view -> {
|
||||
editTextEmailTitle.setFocusable(true);
|
||||
editTextEmailTitle.requestFocus();
|
||||
editTextEmailTitle.append("{{接收时间}}");
|
||||
});
|
||||
|
||||
Button buttonInsertDeviceName = view1.findViewById(R.id.bt_insert_device_name);
|
||||
buttonInsertDeviceName.setOnClickListener(view -> {
|
||||
editTextEmailTitle.setFocusable(true);
|
||||
editTextEmailTitle.requestFocus();
|
||||
editTextEmailTitle.append("{{设备名称}}");
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
//Bark
|
||||
|
@ -13,11 +13,12 @@ public class EmailSettingVo implements Serializable {
|
||||
private String nickname;
|
||||
private String pwd;
|
||||
private String toEmail;
|
||||
private String title;
|
||||
|
||||
public EmailSettingVo() {
|
||||
}
|
||||
|
||||
public EmailSettingVo(String host, String port, Boolean ssl, String fromEmail, String nickname, String pwd, String toEmail) {
|
||||
public EmailSettingVo(String host, String port, Boolean ssl, String fromEmail, String nickname, String pwd, String toEmail, String title) {
|
||||
this.host = host;
|
||||
this.port = port;
|
||||
this.ssl = ssl;
|
||||
@ -25,6 +26,7 @@ public class EmailSettingVo implements Serializable {
|
||||
this.nickname = nickname;
|
||||
this.pwd = pwd;
|
||||
this.toEmail = toEmail;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -29,6 +29,21 @@ public class SmsVo implements Serializable {
|
||||
this.simInfo = simInfo;
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public String getTitleForSend(String titleTemplate) {
|
||||
if (titleTemplate == null || titleTemplate.isEmpty()) titleTemplate = "{{来源号码}}";
|
||||
|
||||
String deviceMark = SettingUtil.getAddExtraDeviceMark().trim();
|
||||
String versionName = SettingUtil.getVersionName();
|
||||
return titleTemplate.replace("{{来源号码}}", mobile).replace("{{APP包名}}", mobile)
|
||||
.replace("{{短信内容}}", content).replace("{{通知内容}}", content)
|
||||
.replace("{{卡槽信息}}", simInfo)
|
||||
.replace("{{接收时间}}", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date))
|
||||
.replace("{{设备名称}}", deviceMark)
|
||||
.replace("{{当前应用版本号}}", versionName)
|
||||
.trim();
|
||||
}
|
||||
|
||||
@SuppressLint("SimpleDateFormat")
|
||||
public String getSmsVoForSend(String ruleSmsTemplate) {
|
||||
String deviceMark = SettingUtil.getAddExtraDeviceMark().trim();
|
||||
@ -45,11 +60,13 @@ public class SmsVo implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
String versionName = SettingUtil.getVersionName();
|
||||
return customSmsTemplate.replace("{{来源号码}}", mobile).replace("{{APP包名}}", mobile)
|
||||
.replace("{{短信内容}}", content).replace("{{通知内容}}", content)
|
||||
.replace("{{卡槽信息}}", simInfo)
|
||||
.replace("{{接收时间}}", new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date))
|
||||
.replace("{{设备名称}}", deviceMark)
|
||||
.replace("{{当前应用版本号}}", versionName)
|
||||
.trim();
|
||||
}
|
||||
|
||||
|
@ -133,7 +133,7 @@ public class SendUtil {
|
||||
if (emailSettingVo != null) {
|
||||
try {
|
||||
SenderMailMsg.sendEmail(logId, handError, emailSettingVo.getHost(), emailSettingVo.getPort(), emailSettingVo.getSsl(), emailSettingVo.getFromEmail(), emailSettingVo.getNickname(),
|
||||
emailSettingVo.getPwd(), emailSettingVo.getToEmail(), smsVo.getMobile(), smsVo.getSmsVoForSend(smsTemplate));
|
||||
emailSettingVo.getPwd(), emailSettingVo.getToEmail(), smsVo.getTitleForSend(emailSettingVo.getTitle()), smsVo.getSmsVoForSend(smsTemplate));
|
||||
} catch (Exception e) {
|
||||
LogUtil.updateLog(logId, 0, e.getMessage());
|
||||
Log.e(TAG, "senderSendMsg: SenderMailMsg error " + e.getMessage());
|
||||
|
@ -3,6 +3,8 @@ package com.idormy.sms.forwarder.utils;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
@ -203,4 +205,19 @@ public class SettingUtil {
|
||||
public static void setPrevNoticeHash(String key, String value) {
|
||||
sp_setting.edit().putString(key, value).apply();
|
||||
}
|
||||
|
||||
//获取当前版本名称
|
||||
public static String getVersionName() {
|
||||
// 获取PackageManager的实例
|
||||
PackageManager packageManager = context.getPackageManager();
|
||||
// getPackageName()是你当前类的包名,0代表是获取版本信息
|
||||
PackageInfo packInfo = null;
|
||||
try {
|
||||
packInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
|
||||
return packInfo.versionName;
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -189,6 +189,102 @@
|
||||
tools:ignore="LabelFor" />
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_sms_template"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="10dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:background="@android:color/white"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/email_title" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="5dp"
|
||||
android:text="@string/custom_templates_tips"
|
||||
android:textSize="11sp" />
|
||||
</LinearLayout>
|
||||
|
||||
<EditText
|
||||
android:id="@+id/editTextEmailTitle"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:autofillHints=""
|
||||
android:inputType="textMultiLine"
|
||||
android:gravity="start|top"
|
||||
android:minLines="1"
|
||||
android:text=""
|
||||
tools:ignore="LabelFor" />
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/bt_insert_sender"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="25dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@color/colorPrimary"
|
||||
android:text="@string/insert_sender"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/bt_insert_extra"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="25dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@color/colorPrimary"
|
||||
android:text="@string/insert_extra"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/bt_insert_time"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="25dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@color/colorPrimary"
|
||||
android:text="@string/insert_time"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/bt_insert_device_name"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="25dp"
|
||||
android:layout_marginStart="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:layout_weight="1"
|
||||
android:background="@color/colorPrimary"
|
||||
android:text="@string/insert_device_name"
|
||||
tools:ignore="ButtonStyle,NestedWeights" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
@ -263,7 +263,6 @@
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/layout_sms_template"
|
||||
android:layout_width="match_parent"
|
||||
|
@ -129,6 +129,7 @@
|
||||
<string name="email_password">Password/Auth Code</string>
|
||||
<string name="email_nickname">Nickname</string>
|
||||
<string name="email_to">Send To</string>
|
||||
<string name="email_title">Email Title</string>
|
||||
<string name="feishu_webhook">Webhook</string>
|
||||
<string name="feishu_secret">Secret (optional)</string>
|
||||
<string name="Corp_ID">Corp ID</string>
|
||||
|
@ -129,6 +129,7 @@
|
||||
<string name="email_password">登录密码/授权码</string>
|
||||
<string name="email_nickname">发件人昵称</string>
|
||||
<string name="email_to">收件地址</string>
|
||||
<string name="email_title">邮件主题</string>
|
||||
<string name="feishu_webhook">Webhook 地址</string>
|
||||
<string name="feishu_secret">加签 Secret (没有可不填)</string>
|
||||
<string name="Corp_ID">Corp ID</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user