Skip to content

Conversation

@braito4
Copy link
Contributor

@braito4 braito4 commented Jan 11, 2026

This PR fixes a few issues in EmailCollector (Dolibarr v22) that can lead to unnecessary OAuth refresh calls, incorrect header parsing in PHPIMAP mode, and missed tracking/filters when some mail servers only provide In-Reply-To (and not References).

File changed:

emailcollector.class.php
Changes
OAuth2 (PHPIMAP) token refresh
Stop forcing refresh on every run ($expire = true).
Refresh only when the token is expired (or will expire within ~30 seconds) when getEndOfLife() is available.
PHPIMAP header decoding + Reply-To
Decode potentially encoded header fields (From, To, Cc, Bcc, Subject) using decodeSMTPSubject() in PHPIMAP mode.
Use the Reply-To header for $replytostring instead of mixing it with in_reply-to.
Tracking/filters: use References + In-Reply-To
When applying EmailCollector filters related to tracking signature, consider In-Reply-To in addition to References.
When building the list of references used to detect Dolibarr tracking IDs, also include In-Reply-To and normalize the list.
Avoid false “outgoing email” classification
When MAIL_FROM_EMAILS_TO_CONSIDER_SENDING is empty or contains empty values, ignore empty entries so it can’t match everything.
Why
Always refreshing OAuth tokens increases latency and can hit provider throttling/limits.
PHPIMAP can return encoded “From:” values; saving them undecoded reduces readability and makes grouping/filtering harder.
Some providers put the previous Message-ID in In-Reply-To but do not populate References. Using both increases the chance of matching track IDs and applying track-related filters correctly.
Empty values in MAIL_FROM_EMAILS_TO_CONSIDER_SENDING can lead to misclassification of incoming emails as outgoing.
How to test (manual)
OAuth refresh: Run the EmailCollector several times; it should no longer refresh the token every execution when the token is still valid.
Header decoding: Process an email with an encoded From:/Subject: (e.g. =?UTF-8?...?=); stored values should be human-readable.
Tracking fallback: Reply to a Dolibarr email where the provider only sets In-Reply-To; EmailCollector should not miss the tracking signature and related filters.
Notes on coding style
The patch is generated from the upstream v22 file and keeps the original indentation/tabs to avoid CI errors like “Line indented incorrectly”.

eldy and others added 4 commits January 10, 2026 18:12
…barr#36845)

* Fix numeric input parsing to support comma as decimal separator

GETPOSTINT()  only handles integer values and fails when input uses a comma as decimal

* Update dispatch.php

* Change GETPOST to GETPOSTFLOAT for price input

---------

Co-authored-by: Laurent Destailleur <[email protected]>
- Refresh OAuth token only when expiring\n- Decode PHPIMAP headers and use Reply-To header\n- Consider In-Reply-To when applying tracking-related filters\n- Ignore empty MAIL_FROM_EMAILS_TO_CONSIDER_SENDING entries
eldy added a commit that referenced this pull request Jan 11, 2026
@eldy eldy added Priority 2 - Medium Bug or Expected functionality. If bug, a feature may be blocked but a workaround is found easily. Priority 1 - High / Blocking This is a bug that make a feature not possible to use or very expected feature. and removed Priority 2 - Medium Bug or Expected functionality. If bug, a feature may be blocked but a workaround is found easily. labels Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Priority 1 - High / Blocking This is a bug that make a feature not possible to use or very expected feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants