Class: Yast::MailAliasesClass
- Inherits:
-
Module
- Object
- Module
- Yast::MailAliasesClass
- Defined in:
- ../../library/general/src/modules/MailAliases.rb
Instance Method Summary (collapse)
-
- (Object) FilterRootAlias
Separates aliases into aliases, root_alias and root_alias_comment.
-
- (Object) GetRootAlias
For use by the Users package.
- - (Object) main
-
- (Object) MergeRootAlias(aliases)
Prepend root alias data to aliases, if set.
-
- (Object) mergeTables(new, old)
Merges mail tables, which are order-preserving maps.
-
- (Object) ReadAliases
Read the aliases table (and separate the root alias).
-
- (Object) SetRootAlias(destinations)
For use by the Users package.
-
- (Object) WriteAliases
Part of Write.
Instance Method Details
- (Object) FilterRootAlias
Separates aliases into aliases, root_alias and root_alias_comment
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File '../../library/general/src/modules/MailAliases.rb', line 69 def FilterRootAlias @root_alias = "" @root_alias_comment = "" @aliases = Builtins.filter(@aliases) do |e| if Ops.get_string(e, "alias", "") == "root" @root_alias = Ops.get_string(e, "destinations", "") @root_alias_comment = Ops.get_string(e, "comment", "") next false end true end nil end |
- (Object) GetRootAlias
For use by the Users package. Does not rely on the internal state, first calls the agent.
186 187 188 189 |
# File '../../library/general/src/modules/MailAliases.rb', line 186 def GetRootAlias return "" if !ReadAliases() @root_alias end |
- (Object) main
47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File '../../library/general/src/modules/MailAliases.rb', line 47 def main # no translatable strings, no textdomain. Yast.import "MailTable" # ---------------------------------------------------------------- # List of maps: $[comment:, alias:, destinations:] (all are strings) # Except root. @aliases = [] # Separated/joined with aliases by read/write/set/export @root_alias = "" # Separated/joined with aliases by read/write/set/export @root_alias_comment = "" end |
- (Object) MergeRootAlias(aliases)
Returns prepend root alias data to aliases, if set
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File '../../library/general/src/modules/MailAliases.rb', line 101 def MergeRootAlias(aliases) aliases = deep_copy(aliases) ret = deep_copy(aliases) if @root_alias != "" ret = Builtins.prepend( ret, "alias" => "root", "destinations" => @root_alias, "comment" => @root_alias_comment ) end deep_copy(ret) end |
- (Object) mergeTables(new, old)
Merges mail tables, which are order-preserving maps. First are the entries of the old map, with values updated from the new one, then the rest of the new map.
125 126 127 128 129 130 131 132 133 134 135 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 |
# File '../../library/general/src/modules/MailAliases.rb', line 125 def mergeTables(new, old) new = deep_copy(new) old = deep_copy(old) # make a true map new_m = Builtins.listmap(new) do |e| { Ops.get_string(e, "key", "") => [ Ops.get_string(e, "comment", ""), Ops.get_string(e, "value", "") ] } end # update old values replaced = Builtins.maplist(old) do |e| k = Ops.get_string(e, "key", "") cv = Ops.get_list(new_m, k, []) if Ops.greater_than(Builtins.size(cv), 0) Ops.set(new_m, k, []) # ok, newly constructed next { "key" => k, "comment" => Ops.get_string(cv, 0, ""), "value" => Ops.get_string(cv, 1, "") } else next { "key" => k, "comment" => Ops.get_string(e, "comment", ""), "value" => Ops.get_string(e, "value", "") } end end # remove already updated values filtered = Builtins.filter(new) do |e| Ops.greater_than( Builtins.size(Ops.get_list(new_m, Ops.get_string(e, "key", ""), [])), 0 ) end Builtins.flatten([replaced, filtered]) end |
- (Object) ReadAliases
Read the aliases table (and separate the root alias)
86 87 88 89 90 91 92 93 94 95 96 97 |
# File '../../library/general/src/modules/MailAliases.rb', line 86 def ReadAliases a_raw = MailTable.Read("aliases") @aliases = Builtins.maplist(a_raw) do |e| { "comment" => Ops.get_string(e, "comment", ""), "alias" => Ops.get_string(e, "key", ""), "destinations" => Ops.get_string(e, "value", "") } end FilterRootAlias() true end |
- (Object) SetRootAlias(destinations)
For use by the Users package. Does not use the internal state, just calls the agent. SuSEconfig or newaliases is NOT called! (TODO: what if it is called while the main module is running?) Errors are reported via Report::Error.
198 199 200 201 202 203 204 205 206 207 208 |
# File '../../library/general/src/modules/MailAliases.rb', line 198 def SetRootAlias(destinations) return false if !ReadAliases() @root_alias = destinations @root_alias_comment = "" # TODO: "created by the ... yast2 module"? return false if !WriteAliases() return false if !MailTable.Flush("aliases") true end |
- (Object) WriteAliases
Part of Write.
169 170 171 172 173 174 175 176 177 178 179 |
# File '../../library/general/src/modules/MailAliases.rb', line 169 def WriteAliases a_raw = Builtins.maplist(MergeRootAlias(@aliases)) do |e| { "comment" => Ops.get_string(e, "comment", ""), "key" => Ops.get_string(e, "alias", ""), "value" => Ops.get_string(e, "destinations", "") } end MailTable.Write("aliases", a_raw) true end |