mirror of
https://github.com/moparisthebest/k-9
synced 2025-02-21 05:01:54 -05:00
Add support for loading parts with DataLocation.ON_DISK
This commit is contained in:
parent
d92be22ce3
commit
bb83fdc0e8
@ -0,0 +1,60 @@
|
|||||||
|
package com.fsck.k9.mailstore;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
import com.fsck.k9.mail.Body;
|
||||||
|
import com.fsck.k9.mail.MessagingException;
|
||||||
|
import com.fsck.k9.mail.internet.RawDataBody;
|
||||||
|
import com.fsck.k9.mail.internet.SizeAware;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
|
||||||
|
|
||||||
|
public class FileBackedBody implements Body, SizeAware, RawDataBody {
|
||||||
|
private final File file;
|
||||||
|
private final String encoding;
|
||||||
|
|
||||||
|
public FileBackedBody(File file, String encoding) {
|
||||||
|
this.file = file;
|
||||||
|
this.encoding = encoding;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public InputStream getInputStream() throws MessagingException {
|
||||||
|
try {
|
||||||
|
return new FileInputStream(file);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw new MessagingException("File not found", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setEncoding(String encoding) throws MessagingException {
|
||||||
|
throw new RuntimeException("not supported");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void writeTo(OutputStream out) throws IOException, MessagingException {
|
||||||
|
InputStream in = getInputStream();
|
||||||
|
try {
|
||||||
|
IOUtils.copy(in, out);
|
||||||
|
} finally {
|
||||||
|
in.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getSize() {
|
||||||
|
return file.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getEncoding() {
|
||||||
|
return encoding;
|
||||||
|
}
|
||||||
|
}
|
@ -725,12 +725,18 @@ public class LocalFolder extends Folder<LocalMessage> implements Serializable {
|
|||||||
part.setBody(multipart);
|
part.setBody(multipart);
|
||||||
multipart.setPreamble(preamble);
|
multipart.setPreamble(preamble);
|
||||||
multipart.setEpilogue(epilogue);
|
multipart.setEpilogue(epilogue);
|
||||||
} else if (dataLocation != DataLocation.MISSING) {
|
} else if (dataLocation == DataLocation.IN_DATABASE) {
|
||||||
String encoding = cursor.getString(7);
|
String encoding = cursor.getString(7);
|
||||||
byte[] data = cursor.getBlob(10);
|
byte[] data = cursor.getBlob(10);
|
||||||
|
|
||||||
Body body = new BinaryMemoryBody(data, encoding);
|
Body body = new BinaryMemoryBody(data, encoding);
|
||||||
part.setBody(body);
|
part.setBody(body);
|
||||||
|
} else if (dataLocation == DataLocation.ON_DISK) {
|
||||||
|
String encoding = cursor.getString(7);
|
||||||
|
|
||||||
|
File file = localStore.getAttachmentFile(Long.toString(id));
|
||||||
|
Body body = new FileBackedBody(file, encoding);
|
||||||
|
part.setBody(body);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user