-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[16.0] Update fetchmail_server_folder #3222
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
Conversation
ikus060
commented
Mar 6, 2025
- Update fields description for clarity
- Support fetch_last_day_only to fetch only 24 hours of emails
- Process emails in reverse order
- Use BODY.PEEK to avoid marking email as seen
- Support email field 'reply_to' to matching
- Improve logging
- Relayout view to group related fields
|
Hi @NL66278, |
| ) | ||
| active = fields.Boolean(default=True) | ||
| active = fields.Boolean( | ||
| string="Active", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Odoo will provide this capitalized name automatically, therefore should not be specified according to OCA guidelines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks I did not know
|
|
||
| def get_criteria(self): | ||
| return "UNDELETED" if not self.fetch_unseen_only else "UNSEEN UNDELETED" | ||
| criteria = "UNDELETED" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why replace one clear line, with three in the end doing the same?
If you want to improve it, take away the not operator:
return "UNSEEN UNDELETED" if self.fetch_unseen_only else "UNDELETED"
or, as you might still add the 24 hour crtierium:
criteria = "UNSEEN UNDELETED" if self.fetch_unseen_only else "UNDELETED"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one clear line
Let’s say clarity is subjective and differs from one individual to another.
Will make the changes
NL66278
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your contribution! To proceed a few things are needed. The first one is to locally use pre-commit before you push your changes. Use a pip virtual environment and pip install pre-commit. After activation of the virtual environment run pre-commit install in your repo directory. This will make your changes pass the pre-commit tests what is really required for a merge.
Another thing is to change strings on fields and help sparingly, as this will necessitate also new translations. Having said that your texts are in many cases a real improvement.
If you could add some unit test for the new functions, that would be nice, preventing a decrease in coverage.
|
I've make the requested changes in addition to running pre-commit hook. |
|
@ikus060 Thank you for that. However pre-commit job is still complaining. Coud you run And if possible squash your changes into a single commit. |
70ca8df to
bd2ad4a
Compare
| <field | ||
| name="model_order" | ||
| placeholder="name asc" | ||
| attrs="{'readonly': [('match_first','==',False)], 'required': [('match_first','==',True)]}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what happened here, but the string starting with 'required'could go on the next line, under attrs (or under readonly).
| <group> | ||
| <separator string="Matching Options" /> | ||
| <group colspan="2"> | ||
| <field |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The field element should be indented 4 spaces under group, not sure why pre-commit prettify did not pick this up.
|
@ikus060 Just some small remarks on the xml formatting and we should be good to go... |
bd2ad4a to
f00334b
Compare
|
Here another tentative. Sorry for all the noise. I'm not used to OCA code policies. See my comments for #3017 |
|
@ikus060 No problem. They are here: https://github.com/OCA/odoo-community.org/blob/master/website/Contribution/CONTRIBUTING.rst |
NL66278
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 LGTM
|
Is there something blocking the merge ? |
zamberjo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your pr, I would like to point out a few points I have observed.
| return "UNDELETED" if not self.fetch_unseen_only else "UNSEEN UNDELETED" | ||
| criteria = "UNSEEN UNDELETED" if self.fetch_unseen_only else "UNDELETED" | ||
| if self.fetch_last_day_only: | ||
| yesterday = (datetime.utcnow() - timedelta(days=1)).strftime("%d-%b-%Y") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it is preferable to use the tools already included in Odoo.
| yesterday = (datetime.utcnow() - timedelta(days=1)).strftime("%d-%b-%Y") | |
| yesterday = fields.Date.subtract(fields.Date.context_today(self), days=1).strftime("%d-%b-%Y") |
| criteria = "UNSEEN UNDELETED" if self.fetch_unseen_only else "UNDELETED" | ||
| if self.fetch_last_day_only: | ||
| yesterday = (datetime.utcnow() - timedelta(days=1)).strftime("%d-%b-%Y") | ||
| criteria = f"SINCE {yesterday} " + criteria |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A little more legible
| criteria = f"SINCE {yesterday} " + criteria | |
| criteria = f"SINCE {yesterday} {criteria}" |
| """Select a single message from a folder.""" | ||
| self.ensure_one() | ||
| result, msgdata = connection.fetch(msgid, "(RFC822)") | ||
| result, msgdata = connection.fetch(msgid, "(BODY.PEEK[])") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think this can be configurable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hum, good point. I would recommand to do something similar to flag_nonmatching.
I could introduce a new fields to mark the email as seen if matching. and another fields to mark the email as seed if not matching ?
The idea is to let the admin decide which email should be mark as seen.
Maybe you have a different proposal ?
To make it symetric with flag_nonmatching, I could also add a field flag_matching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ikus060 @zamberjo Would definitely be nice to have this configurable! I do not quite see what the purpose would be of a field flag_matching. The idea of flagging is to make clear to the user that some kind of manual action might be needed, as we do not know what to do with the email in Odoo. As for configuring whether to use BODY.PEEK or RFC822 I would prefer a selection field. (And then preferably have RFC822 as the default, as that is the current way it works and on which organizations might rely). The idea would by default be that users only occasionally look at the mailbox, and then can assume UNSEEN mails have not been fetched by Odoo. On the other hand, if in some organizations somebody must check the mailbox regularly and actually read the emails, BODY.PEEK would be appropriate to make clear to the user which mails this user still needs to deal with.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @NL66278, imho the best thing to do is to create a selection field leaving RFC822 as default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the only difference between BODY.PEEK and RFC822 is that the latter marks the e-mail as read, it would be preferable to offer a more flexible configuration to support other usage scenarios, including :
- Marking all e-mails as read (default): This is the previous behaviour of this addons. Any email consume by the addons are marked as Seen.
- Mark matching e-mails as read : When email is not matchhing anything, then the email is left Unseed.
- Do not mark e-mails as read : This is the behaviour I'm looking for. My use case is to have Odoo consume all email from inbox and attach matching email to the right ressources for tracking and archiving. Users continue to use their mailbox as usual.
If you approve this direction. Do you still recommand a selection field ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ikus060 Having three options I think actually strengthens the case for a selection field.
- Update fields description for clarity - Support fetch_last_day_only to fetch only 24 hours of emails - Process emails in reverse order - Use BODY.PEEK to avoid marking email as seen - Support email field 'reply_to' to matching - Improve logging - Relayout view to group related fields - Add `seen` selection field Add `seen` selection field
f00334b to
0791fdc
Compare
|
Hello All, I took some time to update this Pull Request with the changes recommended. |
|
@zamberjo I think this is ready for merge now. Can you also have another look? |
zamberjo
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Maybe in the future someone will be interested in configuring that period of time instead of leaving it fixed at 24 hours, but let's leave it like that for the moment.
|
/ocabot merge minor |
|
On my way to merge this fine PR! |
|
@NL66278 your merge command was aborted due to failed check(s), which you can inspect on this commit of 16.0-ocabot-merge-pr-3222-by-NL66278-bump-minor. After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red. |
|
/ocabot merge minor |
|
What a great day to merge this nice PR. Let's do it! |
|
@NL66278 your merge command was aborted due to failed check(s), which you can inspect on this commit of 16.0-ocabot-merge-pr-3222-by-NL66278-bump-minor. After fixing the problem, you can re-issue a merge command. Please refrain from merging manually as it will most probably make the target branch red. |
|
For some reason merge commits fails on tests that ran successfully when submitting the PR. On modules that have nothing to do with this PR. |
|
Conflicts can be resolved by merging this PR: https://github.com/ikus060/server-tools/pull/1 |
[FIX] fetchmail_attach_from_folder: solve conflicts
|
@thomaspaulb It should be merged. |
|
@ikus060 There are still conflicts:
Also, the commits should be squashed after the conflicts are solved. |
|
This PR has the |
|
@thomaspaulb Thanks for getting back to me on this PR. I appreciate that we're moving forward with the merge. But, I want to be transparent about where I'm at: it's been almost a year since I submitted this, and in that time my focus has shifted to other projects. I also no longer have the development environment set up to properly test these changes. I completely understand that everyone involved is volunteering their time, and I'm grateful for that. At the same time, I think this situation highlights how long review cycles can make it challenging for contributors to stay engaged - especially when we need to context-switch back after many months. I now resolve the conflict using Github tools. Let hope it's working as expected. If not, I will need more time to recreate all the setup environment. |
|
@ikus060 I understand where you're coming from. OCA currently has this problem of long review cycles. We're trying at the Board level to see how to fix this, but it's not easy. On the other hand, you don't need a development environment to fix this. You just check out the branch on Git, run some smart git commands, and re-push. If not, this will go stale and some other developer will have to open a new PR and fix it for you. |
|
@thomaspaulb I believe I did everything needed. I don't see any conflict anymore. |
|
@thomaspaulb if I understand it well, this to check verify the unit test code coverage. Am I right ? It seems I need to write new units tests. Am I really required to write those test ? I would prefer not to, as it's not a priority for me. |
|
@ikus060 Where do you get the idea that you have to write new unit tests in order to solve a Git merge conflict? The only thing that's needed, basically, is something like It should be, at max, a 15 min job, if not even that, and not worth the discussion IMO |
|
Ah, I think you looked at the wrong part of the screenshot. It is not required to make the coverage green. The important thing to fix is the merge conflicts, which are visible at the bottom of the screenshot as This branch cannot be rebased due to conflicts. |
|
@ikus060 @thomaspaulb There will be more conflicts after merging my backports of Odoo 18.0 improvements. I made a branch with the improvements offered by @ikus060 based on the backport branch, so I propose first looking at the backport branch and if OK merging, then merging in the improvement branch, which basically is already approved in the reviews here. The branch containing both backport and improvements: https://github.com/Therp/server-tools/tree/patrik-fetchmail-server-folder |
|
@ikus060 Would you have a quick look / review of this branch? If I merge it in, then I can proceed to merge your changes. |
|
Closing this PR. Reopen for 18.0 branch #3510 |

