Skip to content
Permalink
Browse files

set User-Agent when sending email

  • Loading branch information
iNPUTmice committed Jan 23, 2020
1 parent 955053d commit b4346e03a618dfe657b2dbcb2fe9afd4ee35fba8
@@ -46,7 +46,7 @@ dependencies {
def work_version = "2.3.0-rc01"

implementation "androidx.appcompat:appcompat:$appcompat_version"
implementation ('rs.ltt.jmap:jmap-mua:0.2.2') {
implementation ('rs.ltt.jmap:jmap-mua:0.2.3') {
changing = true
}

@@ -0,0 +1,44 @@
/*
* Copyright 2020 Daniel Gultsch
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package rs.ltt.android.util;

import android.content.Context;
import android.content.pm.PackageManager;

import rs.ltt.android.R;

public class UserAgent {

private static final String UNKNOWN = "unknown";


public static String get(final Context context) {
return String.format(
"%s/%s",
context.getString(R.string.app_name),
getVersion(context)
);
}

private static String getVersion(final Context context) {
final String packageName = context.getPackageName();
try {
return context.getPackageManager().getPackageInfo(packageName, 0).versionName;
} catch (PackageManager.NameNotFoundException | RuntimeException e) {
return UNKNOWN;
}
}
}
@@ -30,6 +30,7 @@
import java.util.List;

import rs.ltt.android.entity.IdentityWithNameAndEmail;
import rs.ltt.android.util.UserAgent;
import rs.ltt.jmap.common.entity.Email;
import rs.ltt.jmap.common.entity.EmailAddress;
import rs.ltt.jmap.common.entity.EmailBodyPart;
@@ -111,6 +112,7 @@ Email buildEmail(final IdentityWithNameAndEmail identity) {
.inReplyTo(this.inReplyTo)
.to(this.to)
.cc(this.cc)
.userAgent(UserAgent.get(getApplicationContext()))
.subject(this.subject)
.bodyValue(partId, emailBodyValue)
.textBody(emailBodyPart)
@@ -8,9 +8,6 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:3.5.3'
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:2.2.0-rc04"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}

0 comments on commit b4346e0

Please sign in to comment.
You can’t perform that action at this time.