Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add subject & filename config in mail #613

Merged
merged 1 commit into from
Jan 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions acra-mail/src/main/java/org/acra/annotation/AcraMailSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@
package org.acra.annotation;

import android.support.annotation.NonNull;
import android.support.annotation.StringRes;

import org.acra.ACRAConstants;
import org.acra.sender.EmailIntentSender;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
Expand Down Expand Up @@ -51,4 +55,21 @@
* @since 5.0.0
*/
boolean reportAsFile() default true;

/**
* custom file name for the report
*
* @return report file name
* @since 5.0.1
*/
@NonNull String reportFileName() default EmailIntentSender.DEFAULT_REPORT_FILENAME;

/**
* custom email subject.
* Default is "<applicationId> Crash Report"
*
* @return resource id of the custom email subject
* @since 5.0.1
*/
@StringRes int subject() default ACRAConstants.DEFAULT_RES_VALUE;
}
10 changes: 8 additions & 2 deletions acra-mail/src/main/java/org/acra/sender/EmailIntentSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,14 @@
*/
@SuppressWarnings("WeakerAccess")
public class EmailIntentSender implements ReportSender {
public static final String DEFAULT_REPORT_FILENAME = "ACRA-report" + ACRAConstants.REPORTFILE_EXTENSION;

private final CoreConfiguration config;
private final MailSenderConfiguration mailConfig;

public EmailIntentSender(@NonNull CoreConfiguration config) {
this.config = config;
this.mailConfig = ConfigUtils.getPluginConfiguration(config, MailSenderConfiguration.class);
}

@Override
Expand Down Expand Up @@ -206,6 +209,9 @@ private void grantPermission(@NonNull Context context, Intent intent, String pac
*/
@NonNull
protected String buildSubject(@NonNull Context context) {
if (mailConfig.subject() != ACRAConstants.DEFAULT_RES_VALUE) {
return context.getString(mailConfig.subject());
}
return context.getPackageName() + " Crash Report";
}

Expand All @@ -220,8 +226,8 @@ protected String buildSubject(@NonNull Context context) {
protected boolean fillAttachmentList(@NonNull Context context, @NonNull String body, @NonNull List<Uri> attachments) {
final InstanceCreator instanceCreator = new InstanceCreator();
attachments.addAll(instanceCreator.create(config.attachmentUriProvider(), new DefaultAttachmentProvider()).getAttachments(context, config));
if (ConfigUtils.getPluginConfiguration(config, MailSenderConfiguration.class).reportAsFile()) {
final Uri report = createAttachmentFromString(context, "ACRA-report" + ACRAConstants.REPORTFILE_EXTENSION, body);
if (mailConfig.reportAsFile()) {
final Uri report = createAttachmentFromString(context, mailConfig.reportFileName(), body);
if (report != null) {
attachments.add(report);
return true;
Expand Down