1 import { Component } from '@angular/core'
7 } from '@angular/forms'
8 import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'
9 import { first } from 'rxjs'
10 import { EditDialogComponent } from 'src/app/components/common/edit-dialog/edit-dialog.component'
11 import { Correspondent } from 'src/app/data/correspondent'
12 import { DocumentType } from 'src/app/data/document-type'
13 import { MailAccount } from 'src/app/data/mail-account'
16 MailFilterAttachmentType,
17 MailMetadataCorrespondentOption,
18 MailMetadataTitleOption,
20 MailRuleConsumptionScope,
21 } from 'src/app/data/mail-rule'
22 import { CorrespondentService } from 'src/app/services/rest/correspondent.service'
23 import { DocumentTypeService } from 'src/app/services/rest/document-type.service'
24 import { MailAccountService } from 'src/app/services/rest/mail-account.service'
25 import { MailRuleService } from 'src/app/services/rest/mail-rule.service'
26 import { UserService } from 'src/app/services/rest/user.service'
27 import { SettingsService } from 'src/app/services/settings.service'
28 import { CheckComponent } from '../../input/check/check.component'
29 import { NumberComponent } from '../../input/number/number.component'
30 import { SelectComponent } from '../../input/select/select.component'
31 import { SwitchComponent } from '../../input/switch/switch.component'
32 import { TagsComponent } from '../../input/tags/tags.component'
33 import { TextComponent } from '../../input/text/text.component'
35 const ATTACHMENT_TYPE_OPTIONS = [
37 id: MailFilterAttachmentType.Attachments,
38 name: $localize`Only process attachments`,
41 id: MailFilterAttachmentType.Everything,
42 name: $localize`Process all files, including 'inline' attachments`,
46 const CONSUMPTION_SCOPE_OPTIONS = [
48 id: MailRuleConsumptionScope.Attachments,
49 name: $localize`Only process attachments`,
52 id: MailRuleConsumptionScope.EmailOnly,
53 name: $localize`Process message as .eml`,
56 id: MailRuleConsumptionScope.Everything,
57 name: $localize`Process message as .eml and attachments separately`,
61 const ACTION_OPTIONS = [
63 id: MailAction.Delete,
64 name: $localize`Delete`,
68 name: $localize`Move to specified folder`,
71 id: MailAction.MarkRead,
72 name: $localize`Mark as read, don't process read mails`,
76 name: $localize`Flag the mail, don't process flagged mails`,
80 name: $localize`Tag the mail with specified tag, don't process tagged mails`,
84 const METADATA_TITLE_OPTIONS = [
86 id: MailMetadataTitleOption.FromSubject,
87 name: $localize`Use subject as title`,
90 id: MailMetadataTitleOption.FromFilename,
91 name: $localize`Use attachment filename as title`,
94 id: MailMetadataTitleOption.None,
95 name: $localize`Do not assign title from this rule`,
99 const METADATA_CORRESPONDENT_OPTIONS = [
101 id: MailMetadataCorrespondentOption.FromNothing,
102 name: $localize`Do not assign a correspondent`,
105 id: MailMetadataCorrespondentOption.FromEmail,
106 name: $localize`Use mail address`,
109 id: MailMetadataCorrespondentOption.FromName,
110 name: $localize`Use name (or mail address if not available)`,
113 id: MailMetadataCorrespondentOption.FromCustom,
114 name: $localize`Use correspondent selected below`,
119 selector: 'pngx-mail-rule-edit-dialog',
120 templateUrl: './mail-rule-edit-dialog.component.html',
121 styleUrls: ['./mail-rule-edit-dialog.component.scss'],
133 export class MailRuleEditDialogComponent extends EditDialogComponent<MailRule> {
134 accounts: MailAccount[]
135 correspondents: Correspondent[]
136 documentTypes: DocumentType[]
139 service: MailRuleService,
140 activeModal: NgbActiveModal,
141 accountService: MailAccountService,
142 correspondentService: CorrespondentService,
143 documentTypeService: DocumentTypeService,
144 userService: UserService,
145 settingsService: SettingsService
147 super(service, activeModal, userService, settingsService)
152 .subscribe((result) => (this.accounts = result.results))
157 .subscribe((result) => (this.correspondents = result.results))
162 .subscribe((result) => (this.documentTypes = result.results))
166 return $localize`Create new mail rule`
170 return $localize`Edit mail rule`
173 getForm(): FormGroup {
174 return new FormGroup({
175 name: new FormControl(null),
176 account: new FormControl(null),
177 enabled: new FormControl(true),
178 folder: new FormControl('INBOX'),
179 filter_from: new FormControl(null),
180 filter_to: new FormControl(null),
181 filter_subject: new FormControl(null),
182 filter_body: new FormControl(null),
183 filter_attachment_filename_include: new FormControl(null),
184 filter_attachment_filename_exclude: new FormControl(null),
185 maximum_age: new FormControl(null),
186 attachment_type: new FormControl(MailFilterAttachmentType.Attachments),
187 consumption_scope: new FormControl(MailRuleConsumptionScope.Attachments),
188 order: new FormControl(null),
189 action: new FormControl(MailAction.MarkRead),
190 action_parameter: new FormControl(null),
191 assign_title_from: new FormControl(MailMetadataTitleOption.FromSubject),
192 assign_tags: new FormControl([]),
193 assign_document_type: new FormControl(null),
194 assign_correspondent_from: new FormControl(
195 MailMetadataCorrespondentOption.FromNothing
197 assign_correspondent: new FormControl(null),
198 assign_owner_from_rule: new FormControl(true),
202 get showCorrespondentField(): boolean {
204 this.objectForm?.get('assign_correspondent_from')?.value ==
205 MailMetadataCorrespondentOption.FromCustom
209 get showActionParamField(): boolean {
211 this.objectForm?.get('action')?.value == MailAction.Move ||
212 this.objectForm?.get('action')?.value == MailAction.Tag
216 get attachmentTypeOptions() {
217 return ATTACHMENT_TYPE_OPTIONS
220 get actionOptions() {
221 return ACTION_OPTIONS
224 get metadataTitleOptions() {
225 return METADATA_TITLE_OPTIONS
228 get metadataCorrespondentOptions() {
229 return METADATA_CORRESPONDENT_OPTIONS
232 get consumptionScopeOptions() {
233 return CONSUMPTION_SCOPE_OPTIONS