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++; total.value++;
} }
}); });
IProgress progress = (IProgress) session.getProperties() TraceOutputStream.IReport reporter =
.get("mail." + name + ".progress"); (TraceOutputStream.IReport) session.getProperties()
.get("mail." + name + ".reporter");
traceOutput.setReporter(total.value, reporter);
if (chunkSize > 0 && supportsExtension("CHUNKING")) { if (chunkSize > 0 && supportsExtension("CHUNKING")) {
/* /*
* Use BDAT to send the data in chunks. * 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 * from the message content, and b) the message content is
* encoded before we even know that we can use BDAT. * encoded before we even know that we can use BDAT.
*/ */
this.message.writeTo(new FilterOutputStream(bdat()) { this.message.writeTo(bdat(), ignoreList);
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);
finishBdat(); finishBdat();
} else { } else {
this.message.writeTo(new FilterOutputStream(data()) { this.message.writeTo(data(), ignoreList);
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);
finishData(); finishData();
} }
if (progress != null)
progress.finished();
if (sendPartiallyFailed) { if (sendPartiallyFailed) {
// throw the exception, // throw the exception,
// fire TransportEvent.MESSAGE_PARTIALLY_DELIVERED event // fire TransportEvent.MESSAGE_PARTIALLY_DELIVERED event
@ -1409,12 +1389,6 @@ public class SMTPTransport extends Transport {
sendMessageEnd(); sendMessageEnd();
} }
public interface IProgress {
void report(int size, int total);
void finished();
}
/** /**
* The send failed, fix the address arrays to report the failure correctly. * 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 boolean quote = false;
private OutputStream traceOut; 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 * Creates an output stream filter built on top of the specified
* underlying output stream. * underlying output stream.
* *
@ -92,6 +97,8 @@ public class TraceOutputStream extends FilterOutputStream {
traceOut.write(b); traceOut.write(b);
} }
out.write(b); out.write(b);
pos++;
report();
} }
/** /**
@ -114,6 +121,8 @@ public class TraceOutputStream extends FilterOutputStream {
traceOut.write(b, off, len); traceOut.write(b, off, len);
} }
out.write(b, off, len); out.write(b, off, len);
pos += len;
report();
} }
/** /**
@ -143,4 +152,22 @@ public class TraceOutputStream extends FilterOutputStream {
traceOut.write(b); 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.smtp.SMTPTransport;
import com.sun.mail.util.MailConnectException; import com.sun.mail.util.MailConnectException;
import com.sun.mail.util.SocketConnectException; import com.sun.mail.util.SocketConnectException;
import com.sun.mail.util.TraceOutputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
@ -300,8 +301,8 @@ public class EmailService implements AutoCloseable {
properties.put("mail." + protocol + ".dsn.notify", what); properties.put("mail." + protocol + ".dsn.notify", what);
} }
void setProgress(SMTPTransport.IProgress listener) { void setReporter(TraceOutputStream.IReport reporter) {
properties.put("mail." + protocol + ".progress", listener); properties.put("mail." + protocol + ".reporter", reporter);
} }
void setListener(StoreListener listener) { void setListener(StoreListener listener) {

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

Loading…
Cancel
Save