Skip to content

Commit

Permalink
新增:Email发送通道的发件人昵称支持插入标签
Browse files Browse the repository at this point in the history
  • Loading branch information
pppscn committed Jun 9, 2022
1 parent 0c852fc commit b0465ee
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,10 @@ class EmailFragment : BaseFragment<FragmentSendersEmailBinding?>(), View.OnClick
}

override fun initListeners() {
binding!!.btInsertSenderToNickname.setOnClickListener(this)
binding!!.btInsertExtraToNickname.setOnClickListener(this)
binding!!.btInsertTimeToNickname.setOnClickListener(this)
binding!!.btInsertDeviceNameToNickname.setOnClickListener(this)
binding!!.btInsertSender.setOnClickListener(this)
binding!!.btInsertExtra.setOnClickListener(this)
binding!!.btInsertTime.setOnClickListener(this)
Expand All @@ -171,8 +175,25 @@ class EmailFragment : BaseFragment<FragmentSendersEmailBinding?>(), View.OnClick
@SingleClick
override fun onClick(v: View) {
try {
val etNickname: EditText = binding!!.etNickname
val etTitleTemplate: EditText = binding!!.etTitleTemplate
when (v.id) {
R.id.bt_insert_sender_to_nickname -> {
CommonUtils.insertOrReplaceText2Cursor(etNickname, getString(R.string.tag_from))
return
}
R.id.bt_insert_extra_to_nickname -> {
CommonUtils.insertOrReplaceText2Cursor(etNickname, getString(R.string.tag_card_slot))
return
}
R.id.bt_insert_time_to_nickname -> {
CommonUtils.insertOrReplaceText2Cursor(etNickname, getString(R.string.tag_receive_time))
return
}
R.id.bt_insert_device_name_to_nickname -> {
CommonUtils.insertOrReplaceText2Cursor(etNickname, getString(R.string.tag_device_name))
return
}
R.id.bt_insert_sender -> {
CommonUtils.insertOrReplaceText2Cursor(etTitleTemplate, getString(R.string.tag_from))
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ data class Mail(
var mailServerHost: String = "", // 发件箱邮箱服务器地址
var mailServerPort: String = "", // 发件箱邮箱服务器端口
var fromAddress: String = "", // 发件箱
var fromNickname: String = "", // 发件人昵称
var password: String = "", // 发件箱授权码(密码)

var toAddress: ArrayList<String> = ArrayList(), // 直接收件人邮箱
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package com.idormy.sms.forwarder.utils.mail
import android.text.Html
import android.text.Spanned
import android.util.Log
import com.xuexiang.xrouter.utils.TextUtils
import java.io.UnsupportedEncodingException
import java.util.*
import javax.activation.DataHandler
import javax.activation.FileDataSource
Expand Down Expand Up @@ -45,7 +47,16 @@ object MailUtil {
return MimeMessage(session).apply {

// 设置发件箱
setFrom(InternetAddress(mail.fromAddress))
if (TextUtils.isEmpty(mail.fromNickname)) {
setFrom(InternetAddress(mail.fromAddress))
} else {
val nickname = try {
MimeUtility.encodeText(mail.fromNickname)
} catch (e: UnsupportedEncodingException) {
e.printStackTrace()
}
setFrom(InternetAddress("$nickname <${mail.fromAddress}>"))
}

// 设置直接接收者收件箱
val toAddress = mail.toAddress.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ class EmailUtils {
mailServerHost = setting.host.toString()
mailServerPort = setting.port.toString()
fromAddress = setting.fromEmail.toString()
fromNickname = msgInfo.getTitleForSend(setting.nickname.toString())
password = setting.pwd.toString()
toAddress = arrayListOf(setting.toEmail.toString())
subject = title
Expand Down
59 changes: 51 additions & 8 deletions app/src/main/res/layout/fragment_senders_email.xml
Original file line number Diff line number Diff line change
Expand Up @@ -115,26 +115,69 @@
</LinearLayout>

<LinearLayout
android:id="@+id/layout_sms_template_to_nickname"
style="@style/senderBarStyle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:orientation="vertical">

<TextView
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/email_nickname"
android:textStyle="bold" />
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/email_nickname"
android:textStyle="bold" />

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:text="@string/custom_template_tips"
android:textSize="11sp" />

</LinearLayout>

<com.xuexiang.xui.widget.edittext.materialedittext.MaterialEditText
android:id="@+id/et_nickname"
android:layout_width="0dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="5dp"
android:layout_weight="1"
android:singleLine="true"
app:met_clearButton="true" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<com.xuexiang.xui.widget.button.shadowbutton.RippleShadowShadowButton
android:id="@+id/bt_insert_sender_to_nickname"
style="@style/insertButtonStyle"
android:text="@string/insert_sender" />

<com.xuexiang.xui.widget.button.shadowbutton.RippleShadowShadowButton
android:id="@+id/bt_insert_extra_to_nickname"
style="@style/insertButtonStyle"
android:layout_marginStart="5dp"
android:text="@string/insert_extra" />

<com.xuexiang.xui.widget.button.shadowbutton.RippleShadowShadowButton
android:id="@+id/bt_insert_time_to_nickname"
style="@style/insertButtonStyle"
android:layout_marginStart="5dp"
android:text="@string/insert_time" />

<com.xuexiang.xui.widget.button.shadowbutton.RippleShadowShadowButton
android:id="@+id/bt_insert_device_name_to_nickname"
style="@style/insertButtonStyle"
android:layout_marginStart="5dp"
android:text="@string/insert_device_name" />

</LinearLayout>

</LinearLayout>

<LinearLayout
Expand Down

0 comments on commit b0465ee

Please sign in to comment.