Re: [Mutt] #3785: adding an attachment failed with success

2015-10-13 Thread Mutt
#3785: adding an attachment failed with success
-+--
  Reporter:  vinc17  |  Owner:  mutt-dev
  Type:  defect  | Status:  new
  Priority:  major   |  Milestone:
 Component:  mutt|Version:  1.5.24
Resolution:  |   Keywords:
-+--

Comment (by kevin8t8):

 Adding a patch for the attach-message error handling.

-- 
Ticket URL: 
Mutt 
The Mutt mail user agent



Fwd: mutt returns a 256 error code

2015-10-13 Thread mathieu . cier
Hello all, 

I am currently using mutt 1.5.18 within a python script for reporting some 
activities about an embedded linux system. 
I do not get any problem when launching the mutt command within a terminal but 
I get troubles when launching from my python script. 

The command I use is pretty simple : 
echo "body of the mail" | mutt -s "mail's subject" some...@domain.com 

That command is called in the python script by: 
retvalue = os.system(command) 

I check the retvalue returned (which seems to me equivalent to the use of $? 
env variable) and I found out that retvalue is sometimes equal to 256... 
I'm looking for documentations about mutt return codes but didn't find anything 
neither on the web nor on the mutt sources. 

Does anyonee could explaining to me where to obtain docs about such codes 
and/or explaining me the meaning of this 256 return code ? 
I also tried to use the -d2 option in the command line. It works when I use a 
terminal command line but not within my python script and I can't find 
any produced .muttdebug file. 
Any suggestion about that matter ? 

Thanks in advance 

Mathieu 





Re: Fwd: mutt returns a 256 error code

2015-10-13 Thread David Champion
* On 13 Oct 2015, mathieu.c...@free.fr wrote: 
> Hello all, 
> 
> I am currently using mutt 1.5.18 within a python script for reporting some 
> activities about an embedded linux system. 
> I do not get any problem when launching the mutt command within a terminal 
> but I get troubles when launching from my python script. 
> 
> The command I use is pretty simple : 
> echo "body of the mail" | mutt -s "mail's subject" some...@domain.com 
> 
> That command is called in the python script by: 
> retvalue = os.system(command) 
> 
> I check the retvalue returned (which seems to me equivalent to the use of $? 
> env variable) and I found out that retvalue is sometimes equal to 256... 

Hi Mathieu -

The return from python's os.system is not the same as the exit status.
You need os.WEXITSTATUS(os.system(command)), which should be 0, or
success.

256 is not a valid exit code - these are 8-bit quantities. :)

For more details, see:
* pydoc os
* man 2 wait

-- 
David Champion • d...@bikeshed.us


Re: Fwd: mutt returns a 256 error code

2015-10-13 Thread David Champion
* On 13 Oct 2015, David Champion wrote: 
> Hi Mathieu -
> 
> The return from python's os.system is not the same as the exit status.
> You need os.WEXITSTATUS(os.system(command)), which should be 0, or
> success.

I should add that you really should check other values as well -- for
example, if mutt dies a terrible death with a segmentation fault, you'll
see:

code = os.system(cmd)
os.WIFEXITED(code) -> False
os.WIFSIGNALED(code) -> True
os.WTERMSIG(code) -> signal.SIGSEGV

> For more details, see:
>   * pydoc os
>   * man 2 wait

-- 
David Champion • d...@bikeshed.us


Re: Fwd: mutt returns a 256 error code

2015-10-13 Thread Moritz Barsnick
On Tue, Oct 13, 2015 at 20:28:08 +0200, mathieu.c...@free.fr wrote:
> I am currently using mutt 1.5.18

Why? mutt's release cycles are really slow, and this version is old
enough to go to school, is has been seven years since its release.

(Okay, I won't argue against 1.4.x here now... "Release early, release
often." That I like.)

Moritz


Re: Fwd: mutt returns a 256 error code

2015-10-13 Thread Cameron Simpson

On 13Oct2015 20:28, mathieu.c...@free.fr  wrote:
I am currently using mutt 1.5.18 within a python script for reporting some 
activities about an embedded linux system.

I do not get any problem when launching the mutt command within a terminal but 
I get troubles when launching from my python script.

The command I use is pretty simple :
echo "body of the mail" | mutt -s "mail's subject" some...@domain.com

That command is called in the python script by:
retvalue = os.system(command)


BTW, you might consider using subprocess:

 from subprocess import Popen, PIPE

 P = Popen(['mutt', '-s', mail_subject, target_address], stdin=PIPE)
 P.stdin.write(message_body)
 P.stdin.close()
 xit = P.wait()

This avoids all sorts of nasty shell quoting issues that are inherent in your 
os.system() invocation.


Cheers,
Cameron Simpson