This is an automated email from the ASF dual-hosted git repository.
btellier pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/james-project.git
The following commit(s) were added to refs/heads/master by this push:
new 2567adc365 Upgrade Cal4j to 4.1.0 (#2621)
2567adc365 is described below
commit 2567adc365cc4123b62bf1661099de2d51fe438b
Author: Houssem Nasri <[email protected]>
AuthorDate: Mon Feb 3 20:57:13 2025 +0100
Upgrade Cal4j to 4.1.0 (#2621)
---
mailet/icalendar/pom.xml | 1 -
.../james/transport/mailets/ICALToHeader.java | 22 ++++++++++++++--------
.../transport/mailets/model/ICALAttributeDTO.java | 13 ++++++++-----
pom.xml | 6 ++++++
4 files changed, 28 insertions(+), 14 deletions(-)
diff --git a/mailet/icalendar/pom.xml b/mailet/icalendar/pom.xml
index 0ac4dd410d..9c586b2e32 100644
--- a/mailet/icalendar/pom.xml
+++ b/mailet/icalendar/pom.xml
@@ -76,7 +76,6 @@
<dependency>
<groupId>org.mnode.ical4j</groupId>
<artifactId>ical4j</artifactId>
- <version>3.2.9</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
diff --git
a/mailet/icalendar/src/main/java/org/apache/james/transport/mailets/ICALToHeader.java
b/mailet/icalendar/src/main/java/org/apache/james/transport/mailets/ICALToHeader.java
index 5d57f639b9..eb1437cb6e 100644
---
a/mailet/icalendar/src/main/java/org/apache/james/transport/mailets/ICALToHeader.java
+++
b/mailet/icalendar/src/main/java/org/apache/james/transport/mailets/ICALToHeader.java
@@ -20,6 +20,7 @@
package org.apache.james.transport.mailets;
import java.util.Map;
+import java.util.Optional;
import jakarta.mail.MessagingException;
import jakarta.mail.internet.MimeMessage;
@@ -125,20 +126,25 @@ public class ICALToHeader extends GenericMailet {
private void writeToHeaders(Calendar calendar, Mail mail) throws
MessagingException {
MimeMessage mimeMessage = mail.getMessage();
- VEvent vevent = (VEvent) calendar.getComponent("VEVENT");
- addIfPresent(mimeMessage, X_MEETING_METHOD_HEADER,
calendar.getMethod());
+ VEvent vevent = (VEvent) calendar.getComponent("VEVENT")
+ .orElseThrow(() -> new MessagingException("Failed to get VEVENT
component"));
+ addIfPresent(mimeMessage, X_MEETING_METHOD_HEADER,
optionalOf(calendar.getMethod()));
addIfPresent(mimeMessage, X_MEETING_UID_HEADER, vevent.getUid());
- addIfPresent(mimeMessage, X_MEETING_RECURRENCE_ID_HEADER,
vevent.getRecurrenceId());
- addIfPresent(mimeMessage, X_MEETING_SEQUENCE_HEADER,
vevent.getSequence());
+ addIfPresent(mimeMessage, X_MEETING_RECURRENCE_ID_HEADER,
optionalOf(vevent.getRecurrenceId()));
+ addIfPresent(mimeMessage, X_MEETING_SEQUENCE_HEADER,
optionalOf(vevent.getSequence()));
addIfPresent(mimeMessage, X_MEETING_DTSTAMP_HEADER,
vevent.getDateStamp());
}
- private void addIfPresent(MimeMessage mimeMessage, String headerName,
Property property) {
- if (property != null) {
+ public static Optional<? extends Property> optionalOf(Property property) {
+ return Optional.ofNullable(property);
+ }
+
+ private void addIfPresent(MimeMessage mimeMessage, String headerName,
Optional<? extends Property> property) {
+ if (property.isPresent()) {
try {
- mimeMessage.addHeader(headerName, property.getValue());
+ mimeMessage.addHeader(headerName, property.get().getValue());
} catch (MessagingException e) {
- LOGGER.error("Could not add header {} with value {}",
headerName, property.getValue(), e);
+ LOGGER.error("Could not add header {} with value {}",
headerName, property.get().getValue(), e);
}
}
}
diff --git
a/mailet/icalendar/src/main/java/org/apache/james/transport/mailets/model/ICALAttributeDTO.java
b/mailet/icalendar/src/main/java/org/apache/james/transport/mailets/model/ICALAttributeDTO.java
index 37cb232a5f..ce648c3dc5 100644
---
a/mailet/icalendar/src/main/java/org/apache/james/transport/mailets/model/ICALAttributeDTO.java
+++
b/mailet/icalendar/src/main/java/org/apache/james/transport/mailets/model/ICALAttributeDTO.java
@@ -31,6 +31,8 @@ import com.google.common.base.Preconditions;
import net.fortuna.ical4j.model.Calendar;
import net.fortuna.ical4j.model.Property;
import net.fortuna.ical4j.model.component.VEvent;
+import net.fortuna.ical4j.model.property.DtStamp;
+import net.fortuna.ical4j.model.property.Uid;
public class ICALAttributeDTO {
@@ -39,22 +41,23 @@ public class ICALAttributeDTO {
public static class Builder {
public RequiresSender from(Calendar calendar, byte[] originalEvent) {
String ical = new String(originalEvent, StandardCharsets.UTF_8);
- VEvent vevent = (VEvent) calendar.getComponent("VEVENT");
- Optional<String> uid = optionalOf(vevent.getUid());
+ VEvent vevent = (VEvent) calendar.getComponent("VEVENT")
+ .orElseThrow(() -> new RuntimeException("Failed to get VEVENT
component"));
+ Optional<Uid> uid = vevent.getUid();
Optional<String> method = optionalOf(calendar.getMethod());
Optional<String> recurrenceId =
optionalOf(vevent.getRecurrenceId());
Optional<String> sequence = optionalOf(vevent.getSequence());
- Optional<String> dtstamp = optionalOf(vevent.getDateStamp());
+ Optional<DtStamp> dtstamp = vevent.getDateStamp();
Preconditions.checkNotNull(ical);
return sender -> recipient -> replyTo ->
new ICALAttributeDTO(
ical,
- uid, sender.asString(),
+ uid.map(Uid::getValue), sender.asString(),
recipient.asString(),
replyTo.asString(),
- dtstamp, method, sequence,
+ dtstamp.map(DtStamp::getValue), method, sequence,
recurrenceId);
}
diff --git a/pom.xml b/pom.xml
index 7045ddd5d9..251abe1908 100644
--- a/pom.xml
+++ b/pom.xml
@@ -675,6 +675,7 @@
<scala.version>${scala.base}.14</scala.version>
<doclint>none</doclint>
<mockito.version>5.10.0</mockito.version>
+ <ical4j.version>4.1.0</ical4j.version>
<jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>
<javacrumbs.json-unit.version>3.2.7</javacrumbs.json-unit.version>
</properties>
@@ -2811,6 +2812,11 @@
<artifactId>junit-vintage-engine</artifactId>
<version>${junit.vintage.version}</version>
</dependency>
+ <dependency>
+ <groupId>org.mnode.ical4j</groupId>
+ <artifactId>ical4j</artifactId>
+ <version>${ical4j.version}</version>
+ </dependency>
<dependency>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-netty</artifactId>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]