Skip to content
Permalink
Browse files

Add support for adding extra headers to mails sent to mailing lists

Reviewed-by: ehelin
  • Loading branch information
Robin Westberg
Robin Westberg committed Sep 24, 2019
1 parent 2ab7e26 commit 15376a9a692b7782db9211ffec568fda96d33c74
@@ -314,6 +314,7 @@ public void run(Path scratchPath) {
newMail::headerValue));
var filteredEmail = Email.from(newMail)
.replaceHeaders(filteredHeaders)
.headers(bot.headers())
.build();
list.post(filteredEmail);
}
@@ -45,6 +45,7 @@
private final WebrevStorage webrevStorage;
private final Set<String> readyLabels;
private final Map<String, Pattern> readyComments;
private final Map<String, String> headers;
private final URI issueTracker;
private final PullRequestUpdateCache updateCache;

@@ -53,7 +54,7 @@
Set<String> ignoredUsers, Set<Pattern> ignoredComments, URI listArchive, String smtpServer,
HostedRepository webrevStorageRepository, String webrevStorageRef,
Path webrevStorageBase, URI webrevStorageBaseUri, Set<String> readyLabels,
Map<String, Pattern> readyComments, URI issueTracker) {
Map<String, Pattern> readyComments, URI issueTracker, Map<String, String> headers) {
emailAddress = from;
codeRepo = repo;
archiveRepo = archive;
@@ -66,6 +67,7 @@
this.smtpServer = smtpServer;
this.readyLabels = readyLabels;
this.readyComments = readyComments;
this.headers = headers;
this.issueTracker = issueTracker;

this.webrevStorage = new WebrevStorage(webrevStorageRepository, webrevStorageRef, webrevStorageBase,
@@ -125,6 +127,10 @@ WebrevStorage webrevStorage() {
return readyComments;
}

Map<String, String> headers() {
return headers;
}

URI issueTracker() {
return issueTracker;
}
@@ -79,14 +79,19 @@ public String name() {
var censusRepo = configuration.repository(repoConfig.get("census").asString());
var censusRef = configuration.repositoryRef(repoConfig.get("census").asString());

Map<String, String> headers = repoConfig.contains("headers") ?
repoConfig.get("headers").fields().stream()
.collect(Collectors.toMap(JSONObject.Field::name, field -> field.value().asString())) :
Map.of();

var list = EmailAddress.parse(repoConfig.get("list").asString());
var folder = repoConfig.contains("folder") ? repoConfig.get("folder").asString() : configuration.repositoryName(repo);
var bot = new MailingListBridgeBot(from, configuration.repository(repo), archiveRepo,
censusRepo, censusRef,
list, ignoredUsers, ignoredComments, listArchive, listSmtp,
webrevRepo, webrevRef, Path.of(folder),
URIBuilder.base(webrevWeb).build(), readyLabels, readyComments,
issueTracker);
issueTracker, headers);
ret.add(bot);

allListNames.add(list);
@@ -72,7 +72,8 @@ void simpleArchive(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// The mailing list as well
var mailmanServer = MailingListServerFactory.createMailmanServer(listServer.getArchive(), listServer.getSMTP());
@@ -136,7 +137,8 @@ void rememberBridged(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// The mailing list as well
var mailmanServer = MailingListServerFactory.createMailmanServer(listServer.getArchive(), listServer.getSMTP());
@@ -112,7 +112,8 @@ void simpleArchive(TestInfo testInfo) throws IOException {
URIBuilder.base("http://www.test.test/").build(),
Set.of("rfr"), Map.of(ignored.host().getCurrentUserDetails().userName(),
Pattern.compile("ready")),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of("Extra1", "val1", "Extra2", "val2"));

// Populate the projects repository
var localRepo = CheckableRepository.init(tempFolder.path(), author.getRepositoryType());
@@ -188,6 +189,8 @@ void simpleArchive(TestInfo testInfo) throws IOException {
assertEquals(pr.getAuthor().fullName(), mail.author().fullName().orElseThrow());
assertEquals(noreplyAddress(archive), mail.author().address());
assertEquals(from, mail.sender());
assertEquals("val1", mail.headerValue("Extra1"));
assertEquals("val2", mail.headerValue("Extra2"));

// And there should be a webrev
Repository.materialize(webrevFolder.path(), archive.getUrl(), "webrev");
@@ -264,7 +267,8 @@ void reviewComment(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
@@ -351,7 +355,8 @@ void combineComments(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
@@ -433,7 +438,8 @@ void commentThreading(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
@@ -542,7 +548,8 @@ void reviewContext(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
@@ -592,7 +599,8 @@ void multipleReviewContexts(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
@@ -660,7 +668,8 @@ void filterComments(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
@@ -718,7 +727,8 @@ void incrementalChanges(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
@@ -838,7 +848,8 @@ void rebased(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
@@ -930,7 +941,8 @@ void skipAddingExistingWebrev(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var localRepo = CheckableRepository.init(tempFolder.path(), author.getRepositoryType());
@@ -1002,7 +1014,8 @@ void notifyReviewVerdicts(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");
@@ -1085,7 +1098,8 @@ void ignoreComments(TestInfo testInfo) throws IOException {
archive, "webrev", Path.of("test"),
URIBuilder.base("http://www.test.test/").build(),
Set.of(), Map.of(),
URIBuilder.base("http://issues.test/browse/").build());
URIBuilder.base("http://issues.test/browse/").build(),
Map.of());

// Populate the projects repository
var reviewFile = Path.of("reviewfile.txt");

0 comments on commit 15376a9

Please sign in to comment.
You can’t perform that action at this time.