@@ -176,20 +176,32 @@ fn main() {
176
176
. map ( |os_str| os_str. to_string_lossy ( ) . to_string ( ) )
177
177
. unwrap_or ( "???" . to_string ( ) ) ;
178
178
179
- let invocation_ctx = {
180
- let mut out = String :: new ( ) ;
179
+ let subject = format ! ( "{sender}@{hostname}: {summary}" ) ;
180
+
181
+ let body = ( || {
182
+ let mut body = String :: new ( ) ;
183
+ writeln ! (
184
+ & mut body,
185
+ "A process on host {hostname:?} invoked the sendmail binary."
186
+ ) ?;
187
+ writeln ! (
188
+ & mut body,
189
+ "The original message is attached inline to this wrapper message."
190
+ ) ?;
191
+ writeln ! ( & mut body) ?;
192
+ writeln ! ( & mut body, "Invocation args: {args}" ) ?;
193
+ writeln ! ( & mut body) ?;
181
194
writeln ! (
182
- & mut out ,
195
+ & mut body ,
183
196
"uid:{} gid:{} euid:{} egid:{}" ,
184
197
users:: get_current_uid( ) ,
185
198
users:: get_current_gid( ) ,
186
199
users:: get_effective_uid( ) ,
187
200
users:: get_effective_gid( )
188
- )
189
- . unwrap ( ) ;
201
+ ) ?;
190
202
let mut display_or_none = |what, value : Option < OsString > | {
191
203
writeln ! (
192
- & mut out ,
204
+ & mut body ,
193
205
"{what}: {}" ,
194
206
value
195
207
. as_ref( )
@@ -202,28 +214,19 @@ fn main() {
202
214
display_or_none ( "groupname" , users:: get_current_groupname ( ) ) ;
203
215
display_or_none ( "effective username" , users:: get_effective_username ( ) ) ;
204
216
display_or_none ( "effective groupname" , users:: get_effective_groupname ( ) ) ;
205
- writeln ! ( & mut out) . unwrap ( ) ;
206
- writeln ! ( & mut out, "hostname: {}" , whoami:: hostname( ) ) . unwrap ( ) ;
207
- writeln ! ( & mut out, "device name: {}" , whoami:: devicename( ) ) . unwrap ( ) ;
208
- writeln ! ( & mut out, "distro: {}" , whoami:: distro( ) ) . unwrap ( ) ;
209
- writeln ! ( & mut out, "platform: {}" , whoami:: platform( ) ) . unwrap ( ) ;
210
- out
211
- } ;
212
-
213
- let subject = format ! ( "{sender}@{hostname}: {summary}" ) ;
214
- let body = format ! (
215
- r#"A process on host {hostname:?} invoked the sendmail binary.
216
- The original message is attached inline to this wrapper message.
217
-
218
- Invocation args: {args}
219
-
220
- {invocation_ctx}
221
-
222
- (This message was generated by forwad-as-attachment-mta)
223
-
224
-
225
- "#
226
- ) ;
217
+ writeln ! ( & mut body) ?;
218
+ writeln ! ( & mut body, "hostname: {}" , whoami:: hostname( ) ) ?;
219
+ writeln ! ( & mut body, "device name: {}" , whoami:: devicename( ) ) ?;
220
+ writeln ! ( & mut body, "distro: {}" , whoami:: distro( ) ) ?;
221
+ writeln ! ( & mut body, "platform: {}" , whoami:: platform( ) ) ?;
222
+ writeln ! ( & mut body) ?;
223
+ writeln ! (
224
+ & mut body,
225
+ "This message was generated by forwad-as-attachment-mta"
226
+ ) ?;
227
+ std:: result:: Result :: < _ , std:: fmt:: Error > :: Ok ( body)
228
+ } ) ( )
229
+ . expect ( "this is all in-memory and we don't expect formatting to fail" ) ;
227
230
228
231
let envelope = Envelope :: new (
229
232
Some ( config. sender_email . clone ( ) ) ,
0 commit comments