Report progress after buffer

There is still a socket buffer
pull/206/head
M66B 3 years ago
parent 6b3f01c367
commit 0145e93730

@ -1308,8 +1308,10 @@ public class SMTPTransport extends Transport {
total.value++;
}
});
IProgress progress = (IProgress) session.getProperties()
.get("mail." + name + ".progress");
TraceOutputStream.IReport reporter =
(TraceOutputStream.IReport) session.getProperties()
.get("mail." + name + ".reporter");
traceOutput.setReporter(total.value, reporter);
if (chunkSize > 0 && supportsExtension("CHUNKING")) {
/*
* Use BDAT to send the data in chunks.
@ -1320,34 +1322,12 @@ public class SMTPTransport extends Transport {
* from the message content, and b) the message content is
* encoded before we even know that we can use BDAT.
*/
this.message.writeTo(new FilterOutputStream(bdat()) {
private int size = 0;
@Override
public void write(int b) throws IOException {
super.write(b);
size++;
if (progress != null && (size % 1024) == 0)
progress.report(size, total.value);
}
}, ignoreList);
this.message.writeTo(bdat(), ignoreList);
finishBdat();
} else {
this.message.writeTo(new FilterOutputStream(data()) {
private int size = 0;
@Override
public void write(int b) throws IOException {
super.write(b);
size++;
if (progress != null && (size % 1024) == 0)
progress.report(size, total.value);
}
}, ignoreList);
this.message.writeTo(data(), ignoreList);
finishData();
}
if (progress != null)
progress.finished();
if (sendPartiallyFailed) {
// throw the exception,
// fire TransportEvent.MESSAGE_PARTIALLY_DELIVERED event
@ -1409,12 +1389,6 @@ public class SMTPTransport extends Transport {
sendMessageEnd();
}
public interface IProgress {
void report(int size, int total);
void finished();
}
/**
* The send failed, fix the address arrays to report the failure correctly.
*/

@ -33,7 +33,12 @@ public class TraceOutputStream extends FilterOutputStream {
private boolean quote = false;
private OutputStream traceOut;
/**
private int pos = 0;
private int last = 0;
private int total = 0;
private IReport reporter = null;
/**
* Creates an output stream filter built on top of the specified
* underlying output stream.
*
@ -92,6 +97,8 @@ public class TraceOutputStream extends FilterOutputStream {
traceOut.write(b);
}
out.write(b);
pos++;
report();
}
/**
@ -114,6 +121,8 @@ public class TraceOutputStream extends FilterOutputStream {
traceOut.write(b, off, len);
}
out.write(b, off, len);
pos += len;
report();
}
/**
@ -143,4 +152,22 @@ public class TraceOutputStream extends FilterOutputStream {
traceOut.write(b);
}
}
void report() {
if (reporter != null && pos - last > 1024) {
last = pos;
reporter.report(pos, total);
}
}
public void setReporter(int total, IReport reporter) {
this.pos = 0;
this.last = 0;
this.total = total;
this.reporter = reporter;
}
public interface IReport {
void report(int pos, int total);
}
}

@ -42,6 +42,7 @@ import com.sun.mail.pop3.POP3Store;
import com.sun.mail.smtp.SMTPTransport;
import com.sun.mail.util.MailConnectException;
import com.sun.mail.util.SocketConnectException;
import com.sun.mail.util.TraceOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
@ -300,8 +301,8 @@ public class EmailService implements AutoCloseable {
properties.put("mail." + protocol + ".dsn.notify", what);
}
void setProgress(SMTPTransport.IProgress listener) {
properties.put("mail." + protocol + ".progress", listener);
void setReporter(TraceOutputStream.IReport reporter) {
properties.put("mail." + protocol + ".reporter", reporter);
}
void setListener(StoreListener listener) {

@ -43,6 +43,7 @@ import androidx.preference.PreferenceManager;
import com.sun.mail.smtp.SMTPSendFailedException;
import com.sun.mail.smtp.SMTPTransport;
import com.sun.mail.util.TraceOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
@ -684,13 +685,13 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
String via = "via " + ident.host + "/" + ident.user +
" to " + (to == null ? null : TextUtils.join(", ", to));
iservice.setProgress(new SMTPTransport.IProgress() {
iservice.setReporter(new TraceOutputStream.IReport() {
private int progress = -1;
private long last = SystemClock.elapsedRealtime();
@Override
public void report(int size, int total) {
int p = (total == 0 ? 0 : 100 * size / total);
public void report(int pos, int total) {
int p = (total == 0 ? 0 : 100 * pos / total);
if (p > progress) {
progress = p;
long now = SystemClock.elapsedRealtime();
@ -701,11 +702,6 @@ public class ServiceSend extends ServiceBase implements SharedPreferences.OnShar
}
}
}
@Override
public void finished() {
lastProgress = -1;
}
});
// Send message

Loading…
Cancel
Save