Repository navigation
chore: the mail Kamelets can choose, move and delete the emails they read, and mail-sink takes cc, bcc and replyTo (#3170) - #3216
Merged
Conversation
…read, and mail-sink takes cc, bcc, replyTo and contentType (apache#3170) mail-imap-source and ms-exchange-online-imap-oauth-source take folderName, unseen, delete, moveTo, copyTo, peek, skipFailedMessage and four search options: searchFrom, searchTo, searchSubject and searchSubjectOrBody. The search options map to the component's searchTerm.* parameters, so no bean is needed. With a search, the component takes unseen from the search and not from the endpoint, so unseen is passed to both. All new options are optional placeholders without a default: when they are not set, the endpoint URI is the same as before. Folder names and search texts go through RAW(), and the folder options reject % and *, which IMAP reads as wildcards. mail-sink takes cc, bcc, replyTo and contentType. The mail component takes the recipients either all from the To, Cc and Bcc headers or, when there is none, all from the options, so a ce-to or ce-cc header dropped the to, cc and bcc options: with the to option and a ce-cc header, the email went to the copy recipient only. The Kamelet now puts the to, cc and bcc options into the headers, so that a ce-to or ce-cc header replaces only its own option and bcc is always kept. Bcc and Reply-To still cannot come from the message. When contentType is set, it wins over a Content-Type header, which sources such as timer-source set to text/plain on every message. A trust store for a private certificate authority is set with the camel.ssl application properties and camel.component.imaps/smtps/smtp.useGlobalSslContextParameters; the descriptions and the doc pages say how. maxMessagesPerPoll is left out: the fetchSize option already limits the emails of each check, and the component ignores maxMessagesPerPoll while fetchSize is set. The mail-sink Citrus test now also checks cc, Reply-To and the content type. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
davsclaus
force-pushed
the
ci-issue-3170-mail-options
branch
from
November 18, 2026 20:01
fdf5301 to
a32de76
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part of #3170:
mail-imap-sourceandms-exchange-online-imap-oauth-sourcecan read another folder, read emails that are already read, search, and move, copy or delete each email once it is processed.mail-sinktakescc,bcc,replyToandcontentType. Both can trust a private certificate authority.The options
mail-imap-sourceandms-exchange-online-imap-oauth-sourcefolderNamefolderName: "RAW({{?folderName}})"INBOXwhen not set.unseen(boolean)unseen: "{{?unseen}}"andsearchTerm.unseen: "{{?unseen}}"falsealso reads the emails that are already read.delete(boolean)delete: "{{?delete}}"moveTomoveTo: "RAW({{?moveTo}})"copyTocopyTo: "RAW({{?copyTo}})"peek(boolean)peek: "{{?peek}}"skipFailedMessage(boolean)skipFailedMessage: "{{?skipFailedMessage}}"searchFromsearchTerm.from: "RAW({{?searchFrom}})"searchTosearchTerm.to: "RAW({{?searchTo}})"Torecipient.searchSubjectsearchTerm.subject: "RAW({{?searchSubject}})"searchSubjectOrBodysearchTerm.subjectOrBody: "RAW({{?searchSubjectOrBody}})"mail-sinkccCcheader, from{{?cc}}, unless the message hasce-ccbccBccheader, from{{?bcc}}replyToreplyTo=RAW({{?replyTo}})on the endpointcontentTypecontentType=RAW({{?contentType}})on the endpoint; when set, theContent-TypeandCamelMailContentTypeheaders are removedtext/html.default, as in chore: mail-sink can use STARTTLS (#3170) #3174. When they are not set, the optional placeholders drop them, so the endpoint URIs are the same as onmain.searchTerm.*parameters. When several are set, an email must match all of them. With a search, camel-mail takes "unread only" from the search and ignores theunseenendpoint option. Sounseenis passed to both; otherwiseunseen: falsewould have no effect once a search is set.searchFromandsearchToonly against a whole address (FROM "bob"finds nothing, andFROM "BOB@"is rejected withBAD). The descriptions therefore say to give the whole address. Case does not matter.RAW()and patterns. Folder names and search texts keep+, spaces,&and parentheses as written.%and*are IMAP wildcards: withmoveTo: "Done 100%+(y)"the server rejected the move, and the email stayed in the inbox, marked as read. So the three folder options have the pattern^[^\r\n%*]+$.replyToandcontentTypealso have a pattern.mail-sinkrecipients: a fix. camel-mail takes the recipients either all from theTo,CcandBccheaders, or, when there is none, all from the options. Onmain, ace-toorce-ccheader therefore dropped every recipient option. Withto: aliceand ace-cc: bobheader, the email went to bob only. Abccoption would have been lost in the same way. The Kamelet now puts theto,ccandbccoptions into the headers, so ace-toorce-ccheader replaces only its own option.BccandReply-Toheaders from the message are still removed, so these two come only from the options. This changes behaviour for thetooption combined with ace-ccheader: thetorecipients now receive the email too.contentTypewins over the header. camel-mail prefers aContent-Typeheader to itscontentTypeoption. Many sources set that header:timer-source, for example, setstext/plainon every message, so the option alone had no effect in a Pipe from it (the Citrus test showed this). WhencontentTypeis set, the Kamelet removes the header. When it is not set, aContent-Type: text/htmlheader still sends HTML, as before.useGlobalSslContextParameters. The descriptions and doc pages give the application properties:camel.ssl.enabled,camel.ssl.trustStoreandcamel.ssl.trustStorePassword, pluscamel.component.imaps.useGlobalSslContextParameters=truefor the sources, andcamel.component.smtps...orcamel.component.smtp...(withstartTls) for the sink. JavaMail has no property for a trust store file. Itsmail.imaps.ssl.trustturns off certificate checks for the listed hosts, so it is not used.maxMessagesPerPoll. The Kamelets already havefetchSize(default 10), and camel-mail ignoresmaxMessagesPerPollwhilefetchSizeis set. Also left out: the date searches (searchTerm.fromSentDateand the like). The date pattern of camel-mail isyyyy-MM-dd HH:mm:SS, whereSSis milliseconds, so a fixed date is read wrongly. Thenow-24hform can be added later if someone needs it.moveTo, amail-sinkexample withcc,bcc,replyToandcontentType, and the trust store properties.subjectandfromoptions ofmail-sinkare still put into the URI withoutRAW(), so a+in them becomes a space:subject: "C++ build 100% done"arrives asC build 100% done. Thetooption does not have this problem any more, because it now goes through a header. This is left for a separate change, because it changes the endpoint URI of everymail-sink.mail-sink-routenow also setscc,bcc,replyToandcontentType: text/html, and checksCc,Reply-Toand the content type. The Citrus mail server does not showBcc.MailITpasses.Verification
Tested with Camel JBang 4.24.0-SNAPSHOT (
camel run --local-kamelet-dir=kamelets) against GreenMail 2.1 (greenmail/standalone) with IMAP, IMAPS, SMTP and SMTPS. GreenMail had login on, and a server certificate forlocalhostand127.0.0.1, signed by a test CA. For STARTTLS, which GreenMail's SMTP does not offer, I used Mailpit with--smtp-require-starttls. The sources trusted the test CA throughcamel.ssl.*withcamel.component.imaps.useGlobalSslContextParameters=true. The mailboxes were checked over IMAP before and after each run. Each source case ran for several 2-second checks.ms-exchange-online-imap-oauth-sourceneeds a token from Microsoft, so it was not tested against Exchange Online. To test its template, the OAuth authenticator bean was replaced by camel-mail'sDefaultAuthenticator, and everything else was kept, includingmail.imaps.auth.mechanisms=XOAUTH2. GreenMail accepts XOAUTH2 and takes the token as the password. The real Kamelet with a made-up tenant fails to start, as onmain(AADSTS90002: Tenant ... not found).camel get endpoint,mainand this branch:mail-imap-source,mail-sink, and the Exchange templatemoveTo: ProcessedProcessed(created) and marked read; inbox emptydelete: truecopyTo: ArchiveArchivedelete: true+moveTounseen: falseunseen: false+delete: truepeekunsetpeek: truepeek: falsedelete+copyTo, or withmoveToContent-Transfer-Encoding: x-bogus-encoding) before a good one, unsetUnknown encoding; the good email is never readskipFailedMessage: truefolderName: OrdersOrdersonly; the inbox email is untouchedfolderName: "INBOX.Orders Returns+1 (x)",moveTo: "Done+1 (y)"folderNamethat does not existsearchSubject: invoicesearchSubject: invoice+unseen: falsesearchFrom: BOB@EXAMPLE.COMsearchTo: alice@example.comCcsearchSubjectOrBody: REFUNDsearchSubject: "A+B & C 100%"searchFrom+searchSubject(Exchange template)folderName(INBOX.Suppliers, GreenMail's separator),searchFrom,searchSubject,moveToProcessedmoveTo+searchSubject+unseen: false;delete+copyTo;folderName;peekunset andfalse;skipFailedMessage;searchFrom+searchSubjectmail-imap-sourcemain)PKIX path building failedNo subject alternative names matching IP addressmain:to: aliceand ace-cc: bobheaderToto,cc,bcc,replyTo: support+x@example.com,contentType: text/htmlTo), bob (Cc) and carol (Bcc) receive it;Reply-To: support+x@example.com;text/html; carol's copy shows noBccheaderce-to: daveheaderTo: dave; bob and carol still receive itce-cc: daveheaderTo: alice,Cc: dave; carol still receives itContent-Type: text/plainheadertext/html(the option wins)Bcc: daveandReply-To: daveheaders on the messageReply-Tois from the optioncontentType, no header /Content-Type: text/htmlheadertext/plain/text/html, as onmainsmtpswith a trust store (camel.component.smtps.useGlobalSslContextParameters=true)smtpswithout itPKIX path building failedsmtpswith the trust store, IP not in the certificateNo subject alternative names matching IP addresssmtp+startTls: true(Mailpit) with a trust store (camel.component.smtp.useGlobalSslContextParameters=true)Could not convert socket to TLS ... PKIX path building failedMailIT(timer-source to mail-sink, withcc,bcc,replyTo,contentType)./mvnw clean verify -DskipTestsand then./mvnw clean verifypassed from the root. Before building, the library copies of the three Kamelets were refreshed with./mvnw -pl library/camel-kamelets resources:copy-resources@copy-resource-one. The build regeneratedkamelets-index.json.MailITwas run with./mvnw -pl tests/camel-kamelets-itest verify -Denable.integration.tests=Nothing -Dit.test=MailIT.Claude Code on behalf of Claus Ibsen
🤖 Generated with Claude Code