Added send raw dialog

pull/203/head
M66B 3 years ago
parent 2fe70cd971
commit a24784a12b

@ -1401,11 +1401,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
properties.setValue("raw_save", message.id, false); properties.setValue("raw_save", message.id, false);
onMenuRawSave(message); onMenuRawSave(message);
} }
if (properties.getValue("raw_send", message.id)) {
properties.setValue("raw_send", message.id, false);
onMenuRawSend(message);
}
} }
private void clearExpanded(TupleMessageEx message) { private void clearExpanded(TupleMessageEx message) {
@ -4561,7 +4556,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
popupMenu.getMenu().findItem(R.id.menu_share_as_html).setVisible(message.content && BuildConfig.DEBUG); popupMenu.getMenu().findItem(R.id.menu_share_as_html).setVisible(message.content && BuildConfig.DEBUG);
popupMenu.getMenu().findItem(R.id.menu_raw_save).setEnabled(message.uid != null); popupMenu.getMenu().findItem(R.id.menu_raw_save).setEnabled(message.uid != null);
popupMenu.getMenu().findItem(R.id.menu_raw_send).setEnabled(message.uid != null); popupMenu.getMenu().findItem(R.id.menu_raw_send_message).setEnabled(message.uid != null);
popupMenu.getMenu().findItem(R.id.menu_raw_send_thread).setEnabled(message.uid != null);
popupMenu.getMenu().findItem(R.id.menu_raw_save).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP); popupMenu.getMenu().findItem(R.id.menu_raw_save).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP);
popupMenu.getMenu().findItem(R.id.menu_raw_send).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP); popupMenu.getMenu().findItem(R.id.menu_raw_send).setVisible(message.accountProtocol == EntityAccount.TYPE_IMAP);
@ -4646,8 +4642,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} else if (itemId == R.id.menu_raw_save) { } else if (itemId == R.id.menu_raw_save) {
onMenuRawSave(message); onMenuRawSave(message);
return true; return true;
} else if (itemId == R.id.menu_raw_send) { } else if (itemId == R.id.menu_raw_send_message) {
onMenuRawSend(message); onMenuRawSend(message, false);
return true;
} else if (itemId == R.id.menu_raw_send_thread) {
onMenuRawSend(message, true);
return true; return true;
} }
return false; return false;
@ -5302,26 +5301,14 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
} }
} }
private void onMenuRawSend(TupleMessageEx message) { private void onMenuRawSend(TupleMessageEx message, boolean threads) {
if (message.raw == null || !message.raw) { Bundle args = new Bundle();
properties.setValue("raw_send", message.id, true); args.putLongArray("ids", new long[]{message.id});
rawDownload(message); args.putBoolean("threads", threads);
} else
try {
File file = message.getRawFile(context);
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
Intent send = new Intent(Intent.ACTION_SEND);
//send.setPackage(BuildConfig.APPLICATION_ID);
send.putExtra(Intent.EXTRA_STREAM, uri);
send.setType("message/rfc822");
send.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(send); FragmentDialogForwardRaw ask = new FragmentDialogForwardRaw();
} catch (Throwable ex) { ask.setArguments(args);
// java.lang.IllegalArgumentException: Failed to resolve canonical path for ... ask.show(parentFragment.getParentFragmentManager(), "message:raw");
Log.unexpectedError(parentFragment.getParentFragmentManager(), ex);
}
} }
private void rawDownload(TupleMessageEx message) { private void rawDownload(TupleMessageEx message) {

@ -0,0 +1,196 @@
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2021 by Marcel Bokhorst (M66B)
*/
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.core.content.FileProvider;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer;
import java.io.File;
import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.List;
public class FragmentDialogForwardRaw extends FragmentDialogBase {
private boolean enabled;
@NonNull
@Override
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
if (savedInstanceState != null)
enabled = savedInstanceState.getBoolean("fair:enabled");
View dview = LayoutInflater.from(getContext()).inflate(R.layout.dialog_forward_raw, null);
TextView tvRemaining = dview.findViewById(R.id.tvRemaining);
TextView tvOption = dview.findViewById(R.id.tvOption);
tvRemaining.setText(getString(R.string.title_eml_downloaded, "-"));
tvOption.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startActivity(
new Intent(getContext(), ActivitySetup.class)
.putExtra("tab", "connection"));
}
});
NumberFormat NF = NumberFormat.getNumberInstance();
new SimpleTask<long[]>() {
@Override
protected long[] onExecute(Context context, Bundle args) {
long[] ids = args.getLongArray("ids");
boolean threads = args.getBoolean("threads");
List<Long> result = new ArrayList<>();
DB db = DB.getInstance(context);
try {
db.beginTransaction();
List<String> msgids = new ArrayList<>();
for (long id : ids) {
EntityMessage message = db.message().getMessage(id);
if (message == null)
continue;
List<EntityMessage> messages = db.message().getMessagesByThread(
message.account, message.thread, threads ? null : id, null);
if (messages == null)
continue;
for (EntityMessage thread : messages) {
if (msgids.contains(thread.msgid))
continue;
msgids.add(thread.msgid);
result.add(thread.id);
if (thread.raw == null || !thread.raw)
EntityOperation.queue(context, thread, EntityOperation.RAW);
}
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
return Helper.toLongArray(result);
}
@Override
protected void onExecuted(Bundle args, long[] ids) {
DB db = DB.getInstance(getContext());
LiveData<Integer> ld = db.message().liveRaw(ids);
ld.observe(getViewLifecycleOwner(), new Observer<Integer>() {
@Override
public void onChanged(Integer remaining) {
if (remaining == null)
return;
String of = getString(R.string.title_of,
NF.format(ids.length - remaining),
NF.format(ids.length));
tvRemaining.setText(getString(R.string.title_eml_downloaded, of));
if (remaining == 0) {
ld.removeObserver(this);
getArguments().putLongArray("ids", ids);
enabled = true;
setButtonEnabled(enabled);
}
}
});
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, getArguments(), "messages:forward");
return new AlertDialog.Builder(getContext())
.setView(dview)
.setPositiveButton(R.string.title_send, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
send(getArguments().getLongArray("ids"));
}
})
.setNegativeButton(android.R.string.cancel, null)
.create();
}
@Override
public void onStart() {
super.onStart();
setButtonEnabled(enabled);
}
void setButtonEnabled(boolean enabled) {
((AlertDialog) getDialog())
.getButton(AlertDialog.BUTTON_POSITIVE)
.setEnabled(enabled);
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putBoolean("fair:enabled", enabled);
super.onSaveInstanceState(outState);
}
private void send(long[] ids) {
try {
ArrayList<Uri> uris = new ArrayList<>();
for (long id : ids) {
File file = EntityMessage.getRawFile(getContext(), id);
Uri uri = FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID, file);
uris.add(uri);
}
Intent send = new Intent(Intent.ACTION_SEND_MULTIPLE);
send.setPackage(BuildConfig.APPLICATION_ID);
send.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
send.setType("message/rfc822");
send.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(send);
} catch (Throwable ex) {
// java.lang.IllegalArgumentException: Failed to resolve canonical path for ...
Log.unexpectedError(getParentFragmentManager(), ex);
}
}
}

@ -121,7 +121,6 @@ import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.PopupMenu; import androidx.appcompat.widget.PopupMenu;
import androidx.constraintlayout.widget.Group; import androidx.constraintlayout.widget.Group;
import androidx.core.content.FileProvider;
import androidx.core.graphics.ColorUtils; import androidx.core.graphics.ColorUtils;
import androidx.core.view.MenuItemCompat; import androidx.core.view.MenuItemCompat;
import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentActivity;
@ -130,7 +129,6 @@ import androidx.fragment.app.FragmentResultListener;
import androidx.fragment.app.FragmentTransaction; import androidx.fragment.app.FragmentTransaction;
import androidx.lifecycle.Lifecycle; import androidx.lifecycle.Lifecycle;
import androidx.lifecycle.LifecycleOwner; import androidx.lifecycle.LifecycleOwner;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import androidx.localbroadcastmanager.content.LocalBroadcastManager; import androidx.localbroadcastmanager.content.LocalBroadcastManager;
@ -379,8 +377,7 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
private static final int REQUEST_BOUNDARY_RETRY = 22; private static final int REQUEST_BOUNDARY_RETRY = 22;
static final int REQUEST_PICK_CONTACT = 23; static final int REQUEST_PICK_CONTACT = 23;
static final int REQUEST_BUTTONS = 24; static final int REQUEST_BUTTONS = 24;
private static final int REQUEST_ASKED_RAW = 25; private static final int REQUEST_ALL_READ = 25;
private static final int REQUEST_ALL_READ = 26;
static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW"; static final String ACTION_STORE_RAW = BuildConfig.APPLICATION_ID + ".STORE_RAW";
static final String ACTION_DECRYPT = BuildConfig.APPLICATION_ID + ".DECRYPT"; static final String ACTION_DECRYPT = BuildConfig.APPLICATION_ID + ".DECRYPT";
@ -3573,106 +3570,15 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
} }
private void onActionRaw() { private void onActionRaw() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
boolean raw_asked = prefs.getBoolean("raw_asked", false);
if (raw_asked) {
_onActionRaw();
return;
}
Bundle args = new Bundle();
args.putString("question", getString(R.string.title_raw_send));
args.putString("remark", getString(R.string.title_ask_raw));
args.putString("notagain", "raw_asked");
FragmentDialogAsk ask = new FragmentDialogAsk();
ask.setArguments(args);
ask.setTargetFragment(FragmentMessages.this, REQUEST_ASKED_RAW);
ask.show(getParentFragmentManager(), "messages:raw");
}
private void _onActionRaw() {
Bundle args = new Bundle(); Bundle args = new Bundle();
args.putLongArray("ids", getSelection()); args.putLongArray("ids", getSelection());
args.putBoolean("threads", false);
selectionTracker.clearSelection(); selectionTracker.clearSelection();
new SimpleTask<Void>() { FragmentDialogForwardRaw ask = new FragmentDialogForwardRaw();
private Toast toast = null; ask.setArguments(args);
ask.show(getParentFragmentManager(), "messages:raw");
@Override
protected Void onExecute(Context context, Bundle args) {
long[] ids = args.getLongArray("ids");
DB db = DB.getInstance(context);
for (long id : ids) {
EntityMessage message = db.message().getMessage(id);
if (message == null)
continue;
if (message.raw == null || !message.raw)
EntityOperation.queue(context, message, EntityOperation.RAW);
}
return null;
}
@Override
protected void onExecuted(Bundle args, Void data) {
long[] ids = args.getLongArray("ids");
final Context context = getContext();
DB db = DB.getInstance(context);
final LiveData<Integer> ld = db.message().liveRaw(ids);
ld.observe(getViewLifecycleOwner(), new Observer<Integer>() {
private Integer last = null;
@Override
public void onChanged(Integer remaining) {
if (remaining == null || remaining == 0) {
ld.removeObserver(this);
try {
ArrayList<Uri> uris = new ArrayList<>();
for (long id : ids) {
File file = EntityMessage.getRawFile(context, id);
Uri uri = FileProvider.getUriForFile(context, BuildConfig.APPLICATION_ID, file);
uris.add(uri);
}
Intent send = new Intent(Intent.ACTION_SEND_MULTIPLE);
send.setPackage(BuildConfig.APPLICATION_ID);
send.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
send.setType("message/rfc822");
send.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
context.startActivity(send);
} catch (Throwable ex) {
// java.lang.IllegalArgumentException: Failed to resolve canonical path for ...
Log.unexpectedError(getParentFragmentManager(), ex);
}
} else {
if (!Objects.equals(last, remaining)) {
last = remaining;
String msg = getString(R.string.title_raw_remaining, remaining);
if (toast != null)
toast.cancel();
toast = ToastEx.makeText(context, msg, Toast.LENGTH_SHORT);
toast.show();
}
}
}
});
}
@Override
protected void onException(Bundle args, Throwable ex) {
Log.unexpectedError(getParentFragmentManager(), ex);
}
}.execute(this, args, "messages:forward");
} }
private void onActionMoveSelectionAccount(long account, boolean copy, List<Long> disabled) { private void onActionMoveSelectionAccount(long account, boolean copy, List<Long> disabled) {
@ -6566,10 +6472,6 @@ public class FragmentMessages extends FragmentBase implements SharedPreferences.
case REQUEST_BUTTONS: case REQUEST_BUTTONS:
adapter.notifyDataSetChanged(); adapter.notifyDataSetChanged();
break; break;
case REQUEST_ASKED_RAW:
if (resultCode == RESULT_OK)
_onActionRaw();
break;
case REQUEST_ALL_READ: case REQUEST_ALL_READ:
if (resultCode == RESULT_OK) if (resultCode == RESULT_OK)
markAllRead(); markAllRead();

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<eu.faircode.email.ScrollViewEx xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fadeScrollbars="false"
android:padding="24dp"
android:scrollbarStyle="outsideOverlay">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<eu.faircode.email.FixedTextView
android:id="@+id/tvTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title_raw_send"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvRemark"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/title_eml_remark"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvTitle" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvOption"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:drawableEnd="@drawable/twotone_settings_24"
android:drawablePadding="6dp"
android:text="@string/title_eml_option"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="italic"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvRemark" />
<eu.faircode.email.FixedTextView
android:id="@+id/tvRemaining"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:text="@string/title_eml_downloaded"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvOption" />
</androidx.constraintlayout.widget.ConstraintLayout>
</eu.faircode.email.ScrollViewEx>

@ -122,7 +122,18 @@
<item <item
android:id="@+id/menu_raw_send" android:id="@+id/menu_raw_send"
android:enabled="false"
android:icon="@drawable/twotone_attachment_24" android:icon="@drawable/twotone_attachment_24"
android:title="@string/title_raw_send" /> android:title="@string/title_raw_send">
<menu>
<item
android:id="@+id/menu_raw_send_message"
android:enabled="false"
android:title="@string/title_raw_send_message" />
<item
android:id="@+id/menu_raw_send_thread"
android:enabled="false"
android:title="@string/title_raw_send_thread" />
</menu>
</item>
</menu> </menu>

@ -981,6 +981,8 @@
<string name="title_share_as_html">Share as HTML</string> <string name="title_share_as_html">Share as HTML</string>
<string name="title_raw_save">Save raw message</string> <string name="title_raw_save">Save raw message</string>
<string name="title_raw_send">Send as attachment</string> <string name="title_raw_send">Send as attachment</string>
<string name="title_raw_send_message">Message</string>
<string name="title_raw_send_thread">Conversation</string>
<string name="title_manage_keywords">Manage keywords</string> <string name="title_manage_keywords">Manage keywords</string>
<string name="title_manage_labels">Manage Gmail labels</string> <string name="title_manage_labels">Manage Gmail labels</string>
<string name="title_add_keyword">Add keyword</string> <string name="title_add_keyword">Add keyword</string>
@ -988,8 +990,10 @@
<string name="title_download_all">Download all</string> <string name="title_download_all">Download all</string>
<string name="title_save_all">Save all</string> <string name="title_save_all">Save all</string>
<string name="title_save_eml">Save raw message file</string> <string name="title_save_eml">Save raw message file</string>
<string name="title_raw_remaining">Raw messages to download: %1$d</string>
<string name="title_ask_raw">To forward messages, the raw (original) messages need to be downloaded from the server. This requires an internet connection.</string> <string name="title_eml_remark">To forward messages, the raw (original) messages need to be downloaded from the server. This requires an internet connection.</string>
<string name="title_eml_option">This can prevented by enabling always downloading raw message files in the connection settings</string>
<string name="title_eml_downloaded">Raw messages downloaded: %1$s</string>
<string name="title_buttons">Select buttons</string> <string name="title_buttons">Select buttons</string>
<string name="title_buttons_hint">The actual actions available depend on the account type and configuration</string> <string name="title_buttons_hint">The actual actions available depend on the account type and configuration</string>

Loading…
Cancel
Save