Hello. For example, I now have 13 users, and there are three scenarios: 1. Emails from 5 users will be retained for the last 60 days. 2. Emails from 2 users will be retained for the last 30 days. 3. Emails from 6 users will be retained for the last 7 days. Thank you.
According to your other posts, you want to use POP3, not IMAP. With POP3, the email client typically deletes all emails from the mail server immediately after downloading them. So there are no emails on the server that need to be removed after a certain time period in that case. If you want to use POP3 with the keep option, then you must use external software to remove emails. Plus you must find a way that no client forgets to enable keep option in his mail client when adding the account. And in case IMAP is used, then the client can set this in his email client directly.
I did use POP3 and enable the retention option. What do you recommend for this external software? They know the time of the reservation, have communicated and decided in advance ... Thank you.
wouldn't it be enough to have the virtual_transport = dovecot-lmtp configured using sieve plugin and use a sieve per user like this Code: require ["fileinto", "envelope", "imap4flags", "copy"]; # If the email is sent by the user, file it into the Sent folder if address :matches ["from"] "[email protected]" { fileinto :copy "Sent"; stop; } # Otherwise, file it into the Inbox fileinto :copy "Inbox_imap"; and use a milter for postfix like Code: import Milter import os class SaveSentMilter(Milter.Base): def __init__(self): self.id = Milter.uniqueID() self.from_address = None self.to_addresses = [] self.email_content = [] def envfrom(self, mailfrom, *str): self.from_address = mailfrom return Milter.CONTINUE def envrcpt(self, to, *str): self.to_addresses.append(to) return Milter.CONTINUE def header(self, name, value): self.email_content.append(f"{name}: {value}\n") return Milter.CONTINUE def eoh(self): self.email_content.append("\n") return Milter.CONTINUE def body(self, chunk): self.email_content.append(chunk) return Milter.CONTINUE def eom(self): email_content_str = ''.join(self.email_content) # Save email to Sent folder self.save_to_sent_folder(email_content_str) return Milter.CONTINUE def save_to_sent_folder(self, email_content): # Prepare the Dovecot delivery command delivery_command = f"/usr/lib/dovecot/dovecot-lda -d {self.from_address} -m 'Sent'" # Use a pipe to send the email to Dovecot LDA process = os.popen(delivery_command, 'w') process.write(email_content) process.close() def main(): Milter.factory = SaveSentMilter Milter.runmilter("save_sent_milter", "/var/spool/postfix/milter/save_sent_milter.sock", 5) if __name__ == "__main__": main() did not test the code, it's just a reference to think of how it might be done. Pop3 and Imap may use the same INBOX folder or not, you can change the namespace inbox to have a different folder for inbox = yes or special_use = \Sent Now I think about it, yeah this can get a little more complex. But in theory this would probably be a way to go, just with a little bit more thinking, time and effort. Not sure if there is a ready made solution. There could be a milter for incoming and outcoming only, thus one could do two milters with different actions, probably could be done more elegant too. Pop3-Clients do not access the folders thus only thing what's left would be to setup a cronjob or something to check on the files age and make "the purge" edit: rethinking... using sieve for imap would be bad, just use the milter approach and leave a clean sieve for users