Bug 1787955 - Fix dot-stuffing when posting NNTP article. r=mkmelin
Differential Revision: https://phabricator.services.mozilla.com/D155930 --HG-- extra : amend_source : 71b2650ed7645a88b063b9d2284e54569ff7ed1a
This commit is contained in:
Родитель
fc256b5150
Коммит
8cea8e601a
|
@ -265,13 +265,6 @@ class NntpClient {
|
|||
this._socket.send(CommonUtils.byteStringToArrayBuffer(str).buffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a single dot line to end the data block.
|
||||
*/
|
||||
sendEnd() {
|
||||
this.send("\r\n.\r\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Send a LIST command to get all the groups in the current server.
|
||||
*/
|
||||
|
|
|
@ -67,18 +67,20 @@ class NntpService {
|
|||
].createInstance(Ci.nsIFileInputStream);
|
||||
// PR_RDONLY
|
||||
fstream.init(messageFile, 0x01, 0, 0);
|
||||
let sstream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
|
||||
Ci.nsIScriptableInputStream
|
||||
);
|
||||
sstream.init(fstream);
|
||||
|
||||
while (sstream.available()) {
|
||||
let chunk = sstream.read(65536);
|
||||
client.send(chunk);
|
||||
}
|
||||
sstream.close();
|
||||
let lineInputStream = fstream.QueryInterface(Ci.nsILineInputStream);
|
||||
let hasMore;
|
||||
do {
|
||||
let outLine = {};
|
||||
hasMore = lineInputStream.readLine(outLine);
|
||||
let line = outLine.value;
|
||||
if (line.startsWith(".")) {
|
||||
// Dot stuffing, see rfc3977#section-3.1.1.
|
||||
line = "." + line;
|
||||
}
|
||||
client.send(line + "\r\n");
|
||||
} while (hasMore);
|
||||
fstream.close();
|
||||
client.sendEnd();
|
||||
client.send(".\r\n");
|
||||
};
|
||||
});
|
||||
}
|
||||
|
@ -197,7 +199,7 @@ class NntpService {
|
|||
)}`,
|
||||
];
|
||||
client.send(content.join("\r\n"));
|
||||
client.sendEnd();
|
||||
client.send("\r\n.\r\n");
|
||||
|
||||
newsFolder.removeMessage(messageKey);
|
||||
newsFolder.cancelComplete();
|
||||
|
|
|
@ -1,39 +1,37 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
// Tests that the news can correctly post messages
|
||||
|
||||
var { MailServices } = ChromeUtils.import(
|
||||
"resource:///modules/MailServices.jsm"
|
||||
);
|
||||
var { PromiseTestUtils } = ChromeUtils.import(
|
||||
"resource://testing-common/mailnews/PromiseTestUtils.jsm"
|
||||
);
|
||||
|
||||
function run_test() {
|
||||
var daemon = setupNNTPDaemon();
|
||||
var server = makeServer(NNTP_RFC977_handler, daemon);
|
||||
/**
|
||||
* Test dot is stuffed correctly when posting an article.
|
||||
*/
|
||||
add_task(async function test_nntpPost() {
|
||||
// Setup test server.
|
||||
let daemon = setupNNTPDaemon();
|
||||
let handler = new NNTP_RFC977_handler(daemon);
|
||||
let server = new nsMailServer(() => handler, daemon);
|
||||
server.start();
|
||||
var localserver = setupLocalServer(server.port);
|
||||
var listener = {
|
||||
OnStartRunningUrl() {},
|
||||
OnStopRunningUrl() {
|
||||
localserver.closeCachedConnections();
|
||||
},
|
||||
};
|
||||
registerCleanupFunction(() => server.stop());
|
||||
|
||||
try {
|
||||
MailServices.nntp.postMessage(
|
||||
do_get_file("postings/post1.eml"),
|
||||
"test.empty",
|
||||
localserver.key,
|
||||
listener,
|
||||
null
|
||||
);
|
||||
server.performTest();
|
||||
server.stop();
|
||||
// Send post3.eml to the server.
|
||||
let localServer = setupLocalServer(server.port);
|
||||
let testFile = do_get_file("postings/post3.eml");
|
||||
let urlListener = new PromiseTestUtils.PromiseUrlListener();
|
||||
MailServices.nntp.postMessage(
|
||||
testFile,
|
||||
"test.empty",
|
||||
localServer.key,
|
||||
urlListener,
|
||||
null
|
||||
);
|
||||
await urlListener.promise;
|
||||
|
||||
var thread = gThreadManager.currentThread;
|
||||
while (thread.hasPendingEvents()) {
|
||||
thread.processNextEvent(true);
|
||||
}
|
||||
} catch (e) {
|
||||
server.stop();
|
||||
do_throw(e);
|
||||
}
|
||||
}
|
||||
// Because Nntpd.jsm undone the dot-stuffing, handler.post should be the same
|
||||
// as the original post.
|
||||
equal(handler.post, await IOUtils.readUTF8(testFile.path));
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче