Browse Source

Fixed sending with attachments

main
M66B 6 years ago
parent
commit
83cfee5711
2 changed files with 25 additions and 1 deletions
  1. +3
    -1
      app/src/main/java/eu/faircode/email/FragmentCompose.java
  2. +22
    -0
      app/src/main/java/eu/faircode/email/Helper.java

+ 3
- 1
app/src/main/java/eu/faircode/email/FragmentCompose.java View File

@ -965,9 +965,11 @@ public class FragmentCompose extends FragmentEx {
// Restore attachments // Restore attachments
for (EntityAttachment attachment : attachments) { for (EntityAttachment attachment : attachments) {
File file = EntityAttachment.getFile(context, attachment.id);
attachment.id = null; attachment.id = null;
attachment.message = draft.id; attachment.message = draft.id;
db.attachment().insertAttachment(attachment);
attachment.id = db.attachment().insertAttachment(attachment);
Helper.copy(file, EntityAttachment.getFile(context, attachment.id));
} }
EntityOperation.queue(db, draft, EntityOperation.SEND); EntityOperation.queue(db, draft, EntityOperation.SEND);


+ 22
- 0
app/src/main/java/eu/faircode/email/Helper.java View File

@ -34,8 +34,13 @@ import android.widget.Spinner;
import com.google.android.material.bottomnavigation.BottomNavigationView; import com.google.android.material.bottomnavigation.BottomNavigationView;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import javax.mail.Address; import javax.mail.Address;
@ -137,4 +142,21 @@ public class Helper {
a[0] = a[0].split("\\+")[0]; a[0] = a[0].split("\\+")[0];
return TextUtils.join("@", a); return TextUtils.join("@", a);
} }
static void copy(File src, File dst) throws IOException {
InputStream in = new FileInputStream(src);
try {
OutputStream out = new FileOutputStream(dst);
try {
byte[] buf = new byte[4096];
int len;
while ((len = in.read(buf)) > 0)
out.write(buf, 0, len);
} finally {
out.close();
}
} finally {
in.close();
}
}
} }

Loading…
Cancel
Save