<<< Date Index >>>     <<< Thread Index >>>

[Mutt] #3097: mutt's multi-file -a handling fails for POSIX-compliant getopt()



#3097: mutt's multi-file -a handling fails for POSIX-compliant getopt()

 Under Solaris (or under Linux with env POSIXLY_COMPLAINT=1), mutt's getopt
 handling fails to work correctly when trying to attach multiple files:

 {{{
 mutt -a f1 f2 -- jhawk
 --: unable to attach file.
 }}}

 It turns out that mutt is relying on non-POSIX -compliant behavior of GNU
 getopt, and assuming that GNU getopt will reorder the -- in argv to the
 end of the valid option list and set optind after it. E.g.:
 {{{
 argv[] = { ./mutt, -a, f1, --, f2, jhawk }
 optind=4
 argv[optind] = f2
 }}}
 however this behavior is nonportable. What Solaris' posix-compliant getopt
 does is this:
 {{{
 argv[] = { ./mutt, -a, f1, f2, --, jhawk }
 optind=3
 argv[optind] = f2
 }}}
 This means that under Solaris, mutt tries to attach {{{argv[4]}}}, which
 is --, it fails.

 The attached patch prepends a "+" to the getopt arg string, which
 instructs GNU getopt to behave in a POSIX-compliant fashion, and then
 changes the post-getopt atttachment arg -parsing loop so it does not
 attempt to attach the --, but increments optind past it.

 Tested under Linux and Solaris 10.

-- 
Ticket URL: <http://dev.mutt.org/trac/ticket/3097>