MCPcopy Index your code
hub / github.com/foxcpp/maddy / expandCommand

Method expandCommand

internal/check/command/command.go:160–211  ·  view source on GitHub ↗
(address string)

Source from the content-addressed store, hash-verified

158}
159
160func (s *state) expandCommand(address string) (string, []string) {
161 expArgs := make([]string, len(s.c.cmdArgs))
162
163 for i, arg := range s.c.cmdArgs {
164 expArgs[i] = placeholderRe.ReplaceAllStringFunc(arg, func(placeholder string) string {
165 switch placeholder {
166 case "{auth_user}":
167 if s.msgMeta.Conn == nil {
168 return ""
169 }
170 return s.msgMeta.Conn.AuthUser
171 case "{source_ip}":
172 if s.msgMeta.Conn == nil {
173 return ""
174 }
175 tcpAddr, _ := s.msgMeta.Conn.RemoteAddr.(*net.TCPAddr)
176 if tcpAddr == nil {
177 return ""
178 }
179 return tcpAddr.IP.String()
180 case "{source_host}":
181 if s.msgMeta.Conn == nil {
182 return ""
183 }
184 return s.msgMeta.Conn.Hostname
185 case "{source_rdns}":
186 if s.msgMeta.Conn == nil {
187 return ""
188 }
189 valI, err := s.msgMeta.Conn.RDNSName.Get()
190 if err != nil {
191 return ""
192 }
193 if valI == nil {
194 return ""
195 }
196 return valI.(string)
197 case "{msg_id}":
198 return s.msgMeta.ID
199 case "{sender}":
200 return s.mailFrom
201 case "{rcpts}":
202 return strings.Join(s.rcpts, "\n")
203 case "{address}":
204 return address
205 }
206 return placeholder
207 })
208 }
209
210 return s.c.cmd, expArgs
211}
212
213func (s *state) run(cmdName string, args []string, stdin io.Reader) module.CheckResult {
214 cmd := exec.Command(cmdName, args...)

Callers 4

CheckConnectionMethod · 0.95
CheckSenderMethod · 0.95
CheckRcptMethod · 0.95
CheckBodyMethod · 0.95

Calls 2

StringMethod · 0.45
GetMethod · 0.45

Tested by

no test coverage detected