Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split ContactsCollection mailet #1308

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/tmail-backend/configure/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,11 @@ The mailet configuration requires the following parameters:
* `exchange_type`: type of the exchange. Can be "direct", "fanout", "topic", "headers". Optional, defaults to "direct".

=== Example
This configuration forwards contacts collected by the `ContactsCollection` mailet to OpenPaas through the AMQP protocol.
This configuration forwards contacts extracted by the `ContactExtractor` mailet to OpenPaas through the AMQP protocol.

[source,xml]
----
<mailet match="SenderIsLocal" class="com.linagora.tmail.mailets.ContactsCollection">
<mailet match="SenderIsLocal" class="ContactExtractor">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@HoussemNasri can you adapt this change to memory-app sample mailetcontainer.xml and potentially other apps too?

Frontend team rely on memory app for their test and it is failing java.lang.ClassNotFoundException: com.linagora.tmail.mailets.ContactsCollection. cc @hoangdat @tk-nguyen @tddang-linagora

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's already adapted AFAIK.

image

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe mobile team mount outdated configuration file to container

<attribute>extractedContacts</attribute>
</mailet>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ The user is able to autocomplete over his personal contacts and domain contacts

== Storing account contacts when sending mails

An administrator needs to rely on the `ContactsCollection` mailet in `mailetcontainer.xml` configuration file
in order to extract the recipient contacts of a message and index them asynchronously. This mailet also stores
them as JSON in a specified message attribute.

For example:
An administrator can use a combination of the `ContactExtractor` and `IndexContacts` mailets in the `mailetcontainer.xml` configuration file
in order to extract the recipient contacts of a message and index them asynchronously.

For example, in the configuration below, TMail will extract the list of recipients every time the current user sends an email and store them in the `ExtractedContacts` attribute. Then, the `IndexContacts` mailet will index them to enable the autocomplete feature.
....
<mailet match="SenderIsLocal" class="com.linagora.tmail.mailets.ContactsCollection">
<attribute>ExtractedContacts</attribute>
<mailet match="All" class="ContactExtractor">
<attribute>ExtractedContacts</attribute>
</mailet>
<mailet match="All" class="IndexContacts">
<attribute>ExtractedContacts</attribute>
</mailet>
....

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@
<mailet match="All" class="Sieve"/>
<mailet match="All" class="AddDeliveredToHeader"/>
<mailet match="All" class="org.apache.james.jmap.mailet.filter.JMAPFiltering"/>
<mailet match="SenderIsLocal" class="com.linagora.tmail.mailets.ContactsCollection">
<mailet match="SenderIsLocal" class="ContactExtractor">
<attribute>ContactAttribute1</attribute>
</mailet>
<mailet match="SenderIsLocal" class="com.linagora.tmail.mailets.IndexContacts">
<attribute>ContactAttribute1</attribute>
</mailet>
<mailet match="All" class="com.linagora.tmail.mailets.TmailLocalDelivery"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,10 @@
<mailet match="All" class="Sieve"/>
<mailet match="All" class="AddDeliveredToHeader"/>
<mailet match="All" class="org.apache.james.jmap.mailet.filter.JMAPFiltering"/>
<mailet match="SenderIsLocal" class="com.linagora.tmail.mailets.ContactsCollection">
<mailet match="SenderIsLocal" class="ContactExtractor">
<attribute>ContactAttribute1</attribute>
</mailet>
<mailet match="SenderIsLocal" class="com.linagora.tmail.mailets.IndexContacts">
<attribute>ContactAttribute1</attribute>
</mailet>
<mailet match="All" class="com.linagora.tmail.mailets.TmailLocalDelivery"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import static org.apache.james.data.UsersRepositoryModuleChooser.Implementation.DEFAULT;

import java.io.File;
import java.nio.charset.StandardCharsets;
import java.io.FileInputStream;
import java.net.URI;
import java.nio.file.Path;
import java.util.Optional;
import java.util.UUID;

import jakarta.inject.Singleton;

import org.apache.commons.io.FileUtils;
import org.apache.james.JamesServerBuilder;
import org.apache.james.JamesServerExtension;
Expand All @@ -16,6 +19,12 @@
import org.junit.jupiter.api.extension.RegisterExtension;

import com.github.fge.lambdas.Throwing;
import com.google.inject.AbstractModule;
import com.google.inject.Module;
import com.google.inject.Provides;
import com.linagora.tmail.AmqpUri;
import com.linagora.tmail.OpenPaasModule;
import com.linagora.tmail.configuration.OpenPaasConfiguration;
import com.linagora.tmail.james.app.MemoryConfiguration;
import com.linagora.tmail.james.app.MemoryServer;
import com.linagora.tmail.james.common.LinagoraCalendarEventReplyWithAMQPWorkflowContract;
Expand All @@ -38,12 +47,12 @@ public class MemoryCalendarEventReplyWithAMQPWorkflowTest implements LinagoraCal
Throwing.runnable(() -> FileUtils.copyDirectory(new File(ClassLoader.getSystemClassLoader().getResource(".").getFile()),
confPath.toFile())).run();

// Replace amqp uri in the mailetcontainer_with_amqpforward_openpass.xml and write it to mailetcontainer.xml
Throwing.runnable(() -> {
String sourceContent = FileUtils.readFileToString(confPath.resolve("mailetcontainer_with_amqpforward_openpass.xml").toFile(), StandardCharsets.UTF_8);
String newContent = sourceContent.replace("{{AmqpForwardAttribute_uri}}", amqpExtension.getAmqpUri());
FileUtils.writeStringToFile(confPath.resolve("mailetcontainer.xml").toFile(), newContent, StandardCharsets.UTF_8);
}).run();
// Write content of mailetcontainer_with_amqpforward_openpass.xml to mailetcontainer.xml.
Throwing.runnable(() ->
FileUtils.copyToFile(
new FileInputStream(confPath.resolve("mailetcontainer_with_amqpforward_openpass.xml").toFile()),
confPath.resolve("mailetcontainer.xml").toFile()
)).run();

System.out.println("confPath: " + confPath);
return MemoryConfiguration.builder()
Expand All @@ -53,7 +62,12 @@ public class MemoryCalendarEventReplyWithAMQPWorkflowTest implements LinagoraCal
.build();
})
.server(configuration -> MemoryServer.createServer(configuration)
.overrideWith(new LinagoraTestJMAPServerModule(), new DelegationProbeModule()))
.combineWith(new OpenPaasModule())
.overrideWith(
new LinagoraTestJMAPServerModule(),
new DelegationProbeModule(),
provideOpenPaasConfigurationModule(amqpExtension.getAmqpUri()))
)
.build();

@Override
Expand All @@ -65,4 +79,20 @@ public String randomBlobId() {
public Optional<String> readAMQPContent() {
return Throwing.supplier(() -> amqpExtension.readContent()).get();
}

private static Module provideOpenPaasConfigurationModule(String amqpUri) {
return new AbstractModule() {
@Provides
@Singleton
public OpenPaasConfiguration provideOpenPaasConfiguration() {
return new OpenPaasConfiguration(
AmqpUri.from(amqpUri),
URI.create("http://localhost:8081"),
"user",
"password"
);
}
};

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,10 @@
<mailet match="All" class="Sieve"/>
<mailet match="All" class="AddDeliveredToHeader"/>
<mailet match="All" class="org.apache.james.jmap.mailet.filter.JMAPFiltering"/>
<mailet match="SenderIsLocal" class="com.linagora.tmail.mailets.ContactsCollection">
<mailet match="SenderIsLocal" class="ContactExtractor">
<attribute>ContactAttribute1</attribute>
</mailet>
<mailet match="SenderIsLocal" class="com.linagora.tmail.mailets.IndexContacts">
<attribute>ContactAttribute1</attribute>
</mailet>
<mailet match="All" class="com.linagora.tmail.mailets.TmailLocalDelivery"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,11 @@
<rawSource>rawIcalendar2</rawSource>
<onMailetException>ignore</onMailetException>
</mailet>
<mailet match="SenderIsLocal" class="AmqpForwardAttribute">
<uri>{{AmqpForwardAttribute_uri}}</uri>
<mailet match="SenderIsLocal" class="com.linagora.tmail.mailet.OpenPaasAmqpForwardAttribute">
<attribute>icalendarAsJson2</attribute>
<exchange>james:events</exchange>
<exchange_type>fanout</exchange_type>
<attribute>icalendarAsJson2</attribute>
<routing_key>icalendar_routing_key2</routing_key>
<onMailetException>ignore</onMailetException>
</mailet>
<!-- End of ICAL pipeline -->
<mailet match="All" class="RecipientRewriteTable">
Expand Down Expand Up @@ -106,7 +104,10 @@
<mailet match="All" class="Sieve"/>
<mailet match="All" class="AddDeliveredToHeader"/>
<mailet match="All" class="org.apache.james.jmap.mailet.filter.JMAPFiltering"/>
<mailet match="SenderIsLocal" class="com.linagora.tmail.mailets.ContactsCollection">
<mailet match="SenderIsLocal" class="ContactExtractor">
<attribute>ContactAttribute1</attribute>
</mailet>
<mailet match="SenderIsLocal" class="com.linagora.tmail.mailets.IndexContacts">
<attribute>ContactAttribute1</attribute>
</mailet>
<mailet match="All" class="com.linagora.tmail.mailets.TmailLocalDelivery"/>
Expand Down

This file was deleted.

Loading