Class: Yast::MailServerClass

Inherits:
Module
  • Object
show all
Defined in:
../../src/modules/MailServer.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) Abort

Abort function

Returns:

  • blah blah lahjk



106
107
108
109
110
# File '../../src/modules/MailServer.rb', line 106

def Abort
  #    if(AbortFunction != nil)
  #	return eval(AbortFunction) == true;
  false
end

- (Hash) AutoPackages

Return packages needed to be installed and removed during Autoinstallation to ensure module has all needed software installed.

Returns:

  • (Hash)

    with 2 lists.



813
814
815
816
# File '../../src/modules/MailServer.rb', line 813

def AutoPackages
  # TODO FIXME: your code here...
  { "install" => [], "remove" => [] }
end

- (Object) Check_Mail_Domain

Help funktion to check the DNS Settings



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File '../../src/modules/MailServer.rb', line 136

def Check_Mail_Domain
  _LDAPSettings = Ldap.Export
  _DNSWarning = _("There is no main mail domain defined. Please fix it!")

  # looking if a mail domain exist
  searchmap = {
    "base_dn"      => Ops.get_string(_LDAPSettings, "base_config_dn", ""),
    "filter"       => "objectClass=suseDnsConfiguration",
    "attrs"        => ["suseDefaultBase"],
    "not_found_ok" => false,
    "scope"        => 2
  }
  modulesDns = Convert.to_list(SCR.Read(path(".ldap.search"), searchmap))
  dns_base = Ops.get_string(modulesDns, [0, "suseDefaultBase", 0], "")

  searchmap = {
    "base_dn"      => dns_base,
    "filter"       => "(&(objectClass=dNSZone)(relativeDomainName=@))",
    "not_found_ok" => false,
    "map"          => true,
    "scope"        => 2
  }
  counter = 0
  domains = Convert.convert(
    SCR.Read(path(".ldap.search"), searchmap),
    :from => "any",
    :to   => "map <string, map>"
  )

  if domains == nil || domains == {}
    Popup.Warning(_DNSWarning)
    return
  end
  is_main_domain = false
  Builtins.foreach(domains) do |dn, domain|
    if Ops.get_string(domain, ["suseMailDomainType", 0], "") == "main"
      is_main_domain = true
      raise Break
    end
  end
  if !is_main_domain
    Builtins.y2milestone("no main mail domain")
    Ops.set(_LDAPSettings, "bind_pw", @AdminPassword)
    SCR.Execute(path(".ldap.bind"), _LDAPSettings)
    counter2 = 0
    lastDomain = {}
    lastDn = ""
    # evaluate if there is ONE domain with not containing
    # ".in-addr.arpa" inf the zone Name
    Builtins.foreach(domains) do |dn, domain|
      if Ops.less_than(
          Builtins.size(
            Ops.get_string(Ops.get_list(domain, "zonename", []), 0, "")
          ),
          Builtins.size(".in-addr.arpa")
        ) ||
          Builtins.substring(
            Ops.get_string(Ops.get_list(domain, "zonename", []), 0, ""),
            Ops.subtract(
              Builtins.size(
                Ops.get_string(Ops.get_list(domain, "zonename", []), 0, "")
              ),
              Builtins.size(".in-addr.arpa")
            )
          ) != ".in-addr.arpa"
        Ops.set(
          domain,
          "objectClass",
          Builtins.add(
            Ops.get_list(domain, "objectClass", []),
            "suseMailDomain"
          )
        )
        Ops.set(domain, "suseMailDomainType", ["main"])
        Ops.set(domain, "suseMailDomainMasquerading", ["yes"])
        lastDomain = deep_copy(domain)
        lastDn = dn
        counter2 = Ops.add(counter2, 1)
      end
    end
    if counter2 == 1
      # set the ONE to main domain
      Builtins.y2milestone(
        "Setting main mail domain: %1; %2",
        lastDn,
        lastDomain
      )
      SCR.Write(path(".ldap.modify"), { "dn" => lastDn }, lastDomain)
    else
      # user has to decide
      Report.Error(_DNSWarning)
    end
  end
  nil
end

- (Object) CheckPackages

Check if all needed packages are installed

Returns:

  • true on success



234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
# File '../../src/modules/MailServer.rb', line 234

def CheckPackages
  @pam_ldap_installed = Installed("pam_ldap")
  @nss_ldap_installed = Installed("nss_ldap")
  @procmail_installed = Installed("procmail")
  @cyrus_installed = Installed("cyrus-imapd")
  @postfix_installed = Installed("postfix")
  @fetchmail_installed = Installed("fetchmail")
  @ldap_installed = Installed("yast2-ldap-client")
  @sasl_installed = Installed("cyrus-sasl-plain")
  @saslauthd_installed = Installed("cyrus-sasl-saslauthd")
  @plugins_installed = Installed("yast2-mail-plugins")
  @amavis_installed = Installed("amavisd-new")
  @clamav_installed = Installed("clamav")
  @spamassassin_installed = Installed("spamassassin")
  to_install = ""
  l_to_install = []

  if !@pam_ldap_installed
    l_to_install = Builtins.add(l_to_install, "pam_ldap")
    to_install = Ops.add(to_install, "pam_ldap\n")
  end
  if !@nss_ldap_installed
    l_to_install = Builtins.add(l_to_install, "nss_ldap")
    to_install = Ops.add(to_install, "nss_ldap\n")
  end
  if !@postfix_installed
    l_to_install = Builtins.add(l_to_install, "postfix")
    to_install = Ops.add(to_install, "postfix\n")
  end
  if !@ldap_installed
    l_to_install = Builtins.add(l_to_install, "yast2-ldap-client")
    to_install = Ops.add(to_install, "yast2-ldap-client\n")
  end
  if !@sasl_installed
    l_to_install = Builtins.add(l_to_install, "cyrus-sasl-plain")
    to_install = Ops.add(to_install, "cyrus-sasl-plain\n")
  end
  if !@saslauthd_installed
    l_to_install = Builtins.add(l_to_install, "cyrus-sasl-saslauthd")
    to_install = Ops.add(to_install, "cyrus-sasl-saslauthd\n")
  end
  if !@plugins_installed
    l_to_install = Builtins.add(l_to_install, "yast2-mail-plugins")
    to_install = Ops.add(to_install, "yast2-mail-plugins\n")
  end
  if to_install != ""
    if Report.AnyQuestion(
        "",
        Ops.add(
          Ops.add(
            _("You have not installed all needed packages.") + "\n",
            to_install
          ),
          "\n"
        ),
        Label.InstallButton,
        Label.AbortButton,
        :focus_yes
      )
      Package.DoInstall(l_to_install)
    else
      return false
    end
  end
  true
end

- (Hash) Export

Dump the mail-server settings to a single map (For use by autoinstallation.)

Returns:

  • (Hash)

    Dumped settings (later acceptable by Import ())



789
790
791
792
# File '../../src/modules/MailServer.rb', line 789

def Export
  # TODO FIXME: your code here (return the above mentioned variables)...
  {}
end

- (Boolean) Import(settings)

Get all mail-server settings from the first parameter (For use by autoinstallation.)

Parameters:

  • settings (Hash)

    The YCP structure to be imported.

Returns:

  • (Boolean)

    True on success



780
781
782
783
784
# File '../../src/modules/MailServer.rb', line 780

def Import(settings)
  settings = deep_copy(settings)
  # TODO FIXME: your code here (fill the above mentioned variables)...
  true
end

- (Object) Installed(package)

Is a package installed?

Parameters:

  • package (String)

    package name, without version or .rpm suffix

Returns:

  • true/false



130
131
132
# File '../../src/modules/MailServer.rb', line 130

def Installed(package)
  Package.Installed(package)
end

- (Object) main



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File '../../src/modules/MailServer.rb', line 16

def main
  textdomain "mail"

  Yast.import "Ldap"
  Yast.import "Label"
  Yast.import "Package"
  Yast.import "Popup"
  Yast.import "Progress"
  Yast.import "Report"
  Yast.import "Summary"
  Yast.import "YaPI::MailServer"
  Yast.import "NetworkInterfaces"
  Yast.import "Service"
  Yast.import "Users"

  # Data was modified?
  @modified = false


  @proposal_valid = false

  # Abort function
  # return boolean return true if abort
  @AbortFunction = fun_ref(method(:Modified), "boolean ()")

  # Settings: Define all variables needed for configuration of mail-server
  # True if the modul was started with the option 'setup'.
  @setup = false

  # True if there is server certificate.
  @CertExist = false

  # Map of the mail server global settings.
  @GlobalSettings = {}

  # Map of the mail transport settings.
  @MailTransports = {}

  # Map of the mail server prevention settings.
  @MailPrevention = {}

  # Map of the mail server relaying settings.
  @MailRelaying = {}

  # Map of the mail server local delivery settings.
  @MailLocalDelivery = {}

  # Map of the mail server fetching mail jobs.
  @FetchingMail = {}

  # Map of the mail server local domains.
  @MailLocalDomains = {}

  # Map of the mail server local domains.
  @LDAPDefaults = {}

  # List of the PPP devices
  @PPPCards = []

  # Some additional parameter needed for the configuration.
  @AdminPassword = nil

  # List of the Configuration Modules
  @ModulesTreeContent = [
    [_("Global Settings"), "GlobalSettings"],
    [_("Local Delivery"), "MailLocalDelivery"],
    [_("Mail Transports"), "MailTransports"],
    [_("Mailserver Prevention"), "MailPrevention"],
    [_("Mailserver Relaying"), "MailRelaying"],
    [_("Fetching Mail"), "FetchingMail"],
    [_("Mailserver Domains"), "MailLocalDomains"]
  ]

  @pam_ldap_installed = false
  @nss_ldap_installed = false
  @procmail_installed = false
  @ldap_installed = false
  @cyrus_installed = false
  @postfix_installed = false
  @fetchmail_installed = false
  @sasl_installed = false
  @saslauthd_installed = false
  @plugins_installed = false
  @amavis_installed = false
  @spamassassin_installed = false
  @clamav_installed = false
end

- (Object) Modified

Data was modified?

Returns:

  • true if modified



114
115
116
117
118
119
120
121
122
123
124
125
126
# File '../../src/modules/MailServer.rb', line 114

def Modified
  if Ops.get_boolean(@GlobalSettings, "Changed", false) ||
      Ops.get_boolean(@MailTransports, "Changed", false) ||
      Ops.get_boolean(@MailPrevention, "Changed", false) ||
      Ops.get_boolean(@MailRelaying, "Changed", false) ||
      Ops.get_boolean(@MailLocalDelivery, "Changed", false) ||
      Ops.get_boolean(@FetchingMail, "Changed", false) ||
      Ops.get_boolean(@MailLocalDomains, "Changed", false)
    @modified = true
  end
  Builtins.y2debug("modified=%1", @modified)
  @modified
end

- (Object) Overview

Create an overview table with all configured cards

Returns:

  • table items



804
805
806
807
# File '../../src/modules/MailServer.rb', line 804

def Overview
  # TODO FIXME: your code here...
  []
end

- (Object) Read

Read all mail-server settings

Returns:

  • true on success



303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
# File '../../src/modules/MailServer.rb', line 303

def Read
  # MailServer read dialog caption
  caption = _("Reading the Mail Server Settings")

  steps = 8

  sl = 10

  Builtins.y2milestone("----- Start MailServer::Read -----")

  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    "",
    steps,
    [
      # Progress stage 0/7
      _("Read needed packages"),
      # Progress stage 1/7
      _("Read mail server global settings"),
      # Progress stage 2/7
      _("Read mail server transports"),
      # Progress stage 3/7
      _("Read mail server prevention settings"),
      # Progress stage 4/7
      _("Read mail server relaying settings"),
      # Progress stage 5/7
      _("Read mail server local delivery settings"),
      # Progress stage 6/7
      _("Read mail fetching jobs"),
      # Progress stage 7/7
      _("Read mail server domains")
    ],
    [
      # Progress stage 0/7
      _("Reading packages..."),
      # Progress stage 1/7
      _("Reading mail server global settings..."),
      # Progress stage 2/7
      _("Reading mail server transports..."),
      # Progress stage 3/7
      _("Reading mail server prevention settings..."),
      # Progress stage 4/7
      _("Reading mail server relaying settings..."),
      # Progress stage 5/7
      _("Reading mail server local delivery settings..."),
      # Progress stage 6/3
      _("Reading mail fetching jobs..."),
      # Progress stage 7/7
      _("Reading mail server domains..."),
      # Progress finished
      _("Finished")
    ],
    ""
  )

  # read  packages
  return false if Abort()
  Progress.NextStage
  return false if !CheckPackages()
  Builtins.sleep(sl)

  NetworkInterfaces.Read
  _TMP = NetworkInterfaces.Export("modem")
  Builtins.foreach(
    Convert.convert(
      Ops.get(_TMP, "ppp", {}),
      :from => "map",
      :to   => "map <string, map>"
    )
  ) { |k, v| @PPPCards = Builtins.add(@PPPCards, Ops.add("ppp", k)) }
  _TMP = NetworkInterfaces.Export("isdn")
  Builtins.foreach(
    Convert.convert(
      Ops.get(_TMP, "ipp", {}),
      :from => "map",
      :to   => "map <string, map>"
    )
  ) { |k, v| @PPPCards = Builtins.add(@PPPCards, Ops.add("ipp", k)) }
  _TMP = NetworkInterfaces.Export("dsl")
  Builtins.foreach(
    Convert.convert(
      Ops.get(_TMP, "dsl", {}),
      :from => "map",
      :to   => "map <string, map>"
    )
  ) { |k, v| @PPPCards = Builtins.add(@PPPCards, Ops.add("dsl", k)) }


  # read  global settings
  return false if Abort()
  Progress.NextStage
  @GlobalSettings = YaPI::MailServer.ReadGlobalSettings(@AdminPassword)
  # Error message
  if @GlobalSettings == nil
    Report.Error(_("Cannot read the mail server global settings."))
  end
  Builtins.sleep(sl)

  # read mail transports
  return false if Abort()
  Progress.NextStep
  @MailTransports = YaPI::MailServer.ReadMailTransports(@AdminPassword)
  # Error message
  if @MailTransports == nil
    Report.Error(_("Cannot read mail server transports."))
  end
  Builtins.sleep(sl)

  # read mail preventions
  return false if Abort()
  Progress.NextStage
  @MailPrevention = Convert.convert(
    YaPI::MailServer.ReadMailPrevention(@AdminPassword),
    :from => "any",
    :to   => "map <string, any>"
  )
  # Error message
  if @MailPrevention == nil
    Report.Error(_("Cannot read mail server preventions."))
  end
  Builtins.sleep(sl)

  # read mail realaying
  return false if Abort()
  Progress.NextStage
  @MailRelaying = Convert.convert(
    YaPI::MailServer.ReadMailRelaying(@AdminPassword),
    :from => "any",
    :to   => "map <string, any>"
  )
  # Error message
  if @MailRelaying == nil
    Report.Warning(_("Cannot read the mail server relay settings."))
  end
  Builtins.sleep(sl)

  # read mail local delivery
  return false if Abort()
  Progress.NextStage
  @MailLocalDelivery = Convert.convert(
    YaPI::MailServer.ReadMailLocalDelivery(@AdminPassword),
    :from => "any",
    :to   => "map <string, any>"
  )
  # Error message
  if @MailLocalDelivery == nil
    Report.Warning(
      _("Cannot read the mail server local delivery settings.")
    )
  end
  if Ops.get_string(@MailLocalDelivery, "Type", "") != "none"
    Check_Mail_Domain()
  end
  Builtins.sleep(sl)

  # read mail server fetching jobs
  return false if Abort()
  Progress.NextStage
  @FetchingMail = Convert.convert(
    YaPI::MailServer.ReadFetchingMail(@AdminPassword),
    :from => "any",
    :to   => "map <string, any>"
  )
  # Error message
  if @FetchingMail == nil
    Report.Warning(_("Cannot read the mail server fetching jobs."))
  end
  Builtins.sleep(sl)

  # read mail server local domains
  return false if Abort()
  Progress.NextStage
  @MailLocalDomains = Convert.convert(
    YaPI::MailServer.ReadMailLocalDomains(@AdminPassword),
    :from => "any",
    :to   => "map <string, any>"
  )
  # Error message
  if @MailLocalDomains == nil
    Report.Warning(_("Cannot read the mail server domains."))
  end
  Builtins.sleep(sl)

  return false if Abort()
  # Progress finished
  Progress.NextStage
  Builtins.sleep(sl)

  return false if Abort()
  true
end

- (Object) Summary

Create a textual summary and a list of unconfigured cards

Returns:

  • summary of the current configuration



796
797
798
799
800
# File '../../src/modules/MailServer.rb', line 796

def Summary
  # TODO FIXME: your code here...
  # Configuration summary text for autoyast
  [_("Configuration summary ..."), []]
end

- (Object) Write

Write all mail-server settings

Returns:

  • true on success



498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
# File '../../src/modules/MailServer.rb', line 498

def Write
  # MailServer read dialog caption
  caption = _("Saving Mail Server Configuration")

  steps = 8

  sl = 500
  Builtins.sleep(sl)

  # We do not set help text here, because it was set outside
  Progress.New(
    caption,
    " ",
    steps,
    [
      # Progress stage 1/7
      _("Write mail server global settings"),
      # Progress stage 2/7
      _("Write mail server local delivery settings"),
      # Progress stage 3/7
      _("Write mail server transports"),
      # Progress stage 4/7
      _("Write mail server prevention settings"),
      # Progress stage 5/7
      _("Write mail server relaying settings"),
      # Progress stage 6/3
      _("Write mail fetching jobs"),
      # Progress stage 7/7
      _("Write mail server domains")
    ],
    [
      # Progress stage 1/7
      _("Writing mail server global settings..."),
      # Progress stage 2/7
      _("Writing mail server local delivery settings..."),
      # Progress stage 3/7
      _("Writing mail server transports..."),
      # Progress stage 4/7
      _("Writing mail server prevention settings..."),
      # Progress stage 5/7
      _("Writing mail server relaying settings..."),
      # Progress stage 6/3
      _("Writing mail fetching jobs..."),
      # Progress stage 7/7
      _("Writing mail server domains..."),
      # Progress finished
      _("Finished")
    ],
    ""
  )

  # write
  SCR.Write(path(".sysconfig.mail.MAIL_CREATE_CONFIG"), "no")
  SCR.Write(path(".sysconfig.mail"), nil)

  # write  global settings
  return false if Abort()
  Progress.NextStage
  if Ops.get_boolean(@GlobalSettings, "Changed", false)
    if !YaPI::MailServer.WriteGlobalSettings(
        @GlobalSettings,
        @AdminPassword
      )
      Report.Error(_("Cannot write the mail server global settings."))
    end
  end
  Builtins.sleep(sl)

  # write mail local delivery
  # first we looking for if all the needed packages are installed
  if Ops.get_string(@MailLocalDelivery, "Type", "none") == "procmail"
    if !@procmail_installed
      if Report.AnyQuestion(
          "",
          _("You have not installed all needed packages.") + "\n procmail \n",
          Label.InstallButton,
          Label.AbortButton,
          :focus_yes
        )
        Package.DoInstall(["procmail"])
      else
        return false
      end
    end
  end

  if Ops.greater_than(Service.Status("saslauthd"), 0)
    Service.Start("saslauthd")
    Service.Enable("saslauthd")
  end

  if Ops.get_string(@MailLocalDelivery, "Type", "none") == "cyrus"
    if !@cyrus_installed
      if Report.AnyQuestion(
          "",
          _("You have not installed all needed packages.") + "\n cyrus-imapd \n",
          Label.InstallButton,
          Label.AbortButton,
          :focus_yes
        )
        Package.DoInstall(["cyrus-imapd"])
        SCR.UnmountAgent(path(".etc.imapd_conf"))
      else
        return false
      end
    end
    crypted = Users.CryptPassword(@AdminPassword, "system", "foo")
    SCR.Write(path(".target.passwd.cyrus"), crypted)
    Builtins.y2milestone("--- Enabling cyrus --")
    Service.Enable("cyrus")
  else
    if @cyrus_installed
      Service.Stop("cyrus")
      Service.Disable("cyrus")
    end
  end
  return false if Abort()
  Progress.NextStage
  if Ops.get_boolean(@MailLocalDelivery, "Changed", false)
    if !YaPI::MailServer.WriteMailLocalDelivery(
        @MailLocalDelivery,
        @AdminPassword
      )
      Report.Warning(
        _("Cannot write the mail server local delivery settings.")
      )
    end
    if Ops.get_string(@MailLocalDelivery, "Type", "none") == "cyrus"
      Builtins.y2milestone("--- Stop cyrus --")
      Service.Stop("cyrus")
      Builtins.y2milestone("--- Start cyrus --")
      Service.Start("cyrus")
      Builtins.sleep(10000)
      YaPI::MailServer.CreateRootMailbox(@AdminPassword)
    end
  end
  Builtins.sleep(sl)

  # write mail transports
  return false if Abort()
  Progress.NextStep
  if Ops.get_boolean(@MailTransports, "Changed", false)
    # First we have to clean up TLS Sites
    if !YaPI::MailServer.WriteMailTransports(
        @MailTransports,
        @AdminPassword
      )
      Report.Error(_("Cannot write mail server transports."))
    end
  end
  Builtins.sleep(sl)

  # write mail preventions
  return false if Abort()
  Progress.NextStage
  if Ops.get_boolean(@MailPrevention, "VirusScanning", false)
    to_install = ""
    l_to_install = []
    if !@amavis_installed
      l_to_install = Builtins.add(l_to_install, "amavisd-new")
      to_install = Ops.add(to_install, "\n amavisd-new")
      if !@clamav_installed
        l_to_install = Builtins.add(l_to_install, "clamav")
        to_install = Ops.add(to_install, "\n clamav")
      end
      if !@spamassassin_installed
        l_to_install = Builtins.add(l_to_install, "spamassassin")
        to_install = Ops.add(to_install, "\n spamassassin")
      end
      if !@amavis_installed || !@clamav_installed ||
          !@spamassassin_installed
        if Report.AnyQuestion(
            "",
            Ops.add(
              _("You have not installed all needed packages."),
              to_install
            ),
            Label.InstallButton,
            Label.AbortButton,
            :focus_yes
          )
          Package.DoInstall(l_to_install)
          Builtins.y2milestone("Installing amavis")
        else
          return false
        end
        Service.Start("clamd")
        Service.Start("freshclam")
        Service.Start("amavis")
      end
      Service.Enable("amavis")
      Service.Enable("clamd")
      Service.Enable("freshclam")
    end
  end
  if Ops.get_boolean(@MailPrevention, "Changed", false)
    if !YaPI::MailServer.WriteMailPrevention(
        @MailPrevention,
        @AdminPassword
      )
      Report.Error(_("Cannot write mail server preventions."))
    end
    if Ops.get_boolean(@MailPrevention, "VirusScanning", false)
      Service.Enable("amavis")
      Service.Enable("clamd")
      Service.Enable("freshclam")
      Service.Restart("clamd")
      Service.Restart("freshclam")
      Service.Restart("amavis")
    else
      Service.Stop("clamd")
      Service.Stop("freshclam")
      Service.Stop("amavis")
      Service.Disable("amavis")
      Service.Disable("clamd")
      Service.Disable("freshclam")
    end
  end
  Builtins.sleep(sl)

  # write mail realaying
  return false if Abort()
  Progress.NextStage
  if Ops.get_boolean(@MailRelaying, "Changed", false)
    if !YaPI::MailServer.WriteMailRelaying(@MailRelaying, @AdminPassword)
      Report.Warning(_("Cannot write the mail server relay settings."))
    end
  end
  Builtins.sleep(sl)

  # write mail server fetching jobs
  return false if Abort()
  if Ops.get_list(@FetchingMail, "Items", []) != []
    Service.Enable("fetchmail")
    if !@fetchmail_installed
      if Report.AnyQuestion(
          "",
          _("You have not installed all needed packages.") + "\n fetchmail \n",
          Label.InstallButton,
          Label.AbortButton,
          :focus_yes
        )
        Package.DoInstall(["fetchmail"])
      else
        return false
      end
    end
  else
    Service.Disable("fetchmail") if @fetchmail_installed
  end
  Progress.NextStage
  if Ops.get_boolean(@FetchingMail, "Changed", false)
    if !YaPI::MailServer.WriteFetchingMail(@FetchingMail, @AdminPassword)
      Report.Warning(_("Cannot write the mail server fetching jobs."))
    end
    Service.Restart("fetchmail")
  end
  Builtins.sleep(sl)

  # write mail server local domains
  return false if Abort()
  Progress.NextStage
  if Ops.get_boolean(@MailLocalDomains, "Changed", false)
    if !YaPI::MailServer.WriteMailLocalDomains(
        @MailLocalDomains,
        @AdminPassword
      )
      Report.Warning(_("Cannot write the mail server domains."))
    end
  end
  Builtins.sleep(sl)

  Service.Restart("postfix") if Modified()

  return false if Abort()
  true
end