muquit / mailsend

A program to send mail via SMTP from command line
Other
294 stars 68 forks source link

AIX Switching attachment extensions to lowercase #140

Closed glewis64 closed 5 years ago

glewis64 commented 5 years ago

I have built mailsend for RHEL 6.4 and have successfully tested it using both lowercase PDF file attachments and uppercase PDF file attachments. I then moved onto AIX and have successfully built on this platform. In my testing on AIX, the attachments are always looking for a lowercase .pdf extension even though on the command line I specified the file with an uppercase .PDF extension.

How do I overcome this AIX only issue?

Thanks in advance!

glewis64 commented 5 years ago

AIX is correctly maintaining the case of the specified filename, but it is always changing the extension to lowercase no matter what case was specified on the command line. If I attach MiXeD.pDf, I receive an error saying it can't find MiXeD.pdf

muquit commented 5 years ago

mailsend does not manipulate filenames. For whatever reason, file was passed to mailsend as lower case. You can put some debug messages in smtp.c around line# 707 and see what is going on, something like...

(void) fprintf(stderr,"file: %s\n",a->file_path);

glewis64 commented 5 years ago

Here's what I'm posting on the command line and what I'm receiving back:

$ a" -attach MiXeD.pDf,application/PDF,a <
Error: smtp.c (711) - Could not open file for MiXeD.pdf reading (No such file o) Error: smtp.c (779) - Could not encode attachment MiXeD.pdf
Error: smtp.c (894) - failed to send attachment MiXeD.pdf

Isn't the error message providing me the same information as the debug message?

The file on disk is named MiXeDpDf.pDf

muquit commented 5 years ago

In main.c, please add a line after line#288 to check how the file was passed, e.g.

attach_file=argv[i];
(void) fprintf(stderr,"+++++++++++ attach: '%s'\n",attach_file);
add_attachment_to_list(attach_file);

For easy troubleshooting, Instead of specifying comma separated, please do this:

-mime-type 'application/pdf' -disposition 'attachment' -attach '/full/path/of/MixeD.pDF'

Also do:

/bin/ls -lt '/full/path/of/MixeD.pDF'
glewis64 commented 5 years ago

When I was receiving this error we were beginning to get some smtp errors. We have resolved those errors this morning and now it is no longer messing with the extension of the pdf attachment.

I'll chalk this one off as weird as it is working now. I didn't get to the point of putting in the debug code.

Thanks for your help.

glewis64 commented 5 years ago

Update ... I'm compiling on an AIX6.1 server and mailsend works there. It's when I move it to an AIX7.1 server that it starts changing the extension to lowercase.

Any ideas?

muquit commented 5 years ago

I am not convinced that mailsend is doing it, because there is no such code in it to do such thing, unless there is some kind of bug triggering it. You can put the debug messages in various locations as I suggested earlier to find out when the extension is changing (from input to while it opens the file). Thanks

glewis64 commented 5 years ago

The saga continues …

One of the differences I saw between my AIX build and Linux build was that the AIX mailsend executable was considerably larger than the Linux mailsend executable. In researching a little farther I discovered that the AIX one had embedded OpenSSL inside itself. This was revealed by ldd mailsend and it does not list the openssl libraries. I did an ldd on the Linux mailsend and it did list the openssl libraries. I prefer to have the openssl libraries embedded so I set out to embed them in the Linux version and was successful in doing so. Now the Linux mailsend is switching the attachment extension to lowercase just like the AIX one is. However, it only does this when the mailsend is transmitted and ran from another server. If I run it from the server I built mailsend with, it works.

I added the fprintf's you suggested and here are the results:

Ran mailsend from same server I built on: $ t/plain,i -attach $WRK/MiXeD.pDf,application/pdf,a < +++++++++++ attach: 'NOTES.txt,text/plain,i'
+++++++++++ attach: '/ag1/brp/brpdat/users/ag/wrk/MiXeD.pDf,application/pdf,a' file: NOTES.txt
file: /ag1/brp/brpdat/users/ag/wrk/MiXeD.pDf
Mail sent successfully

Same mailsend executable transmitted and ran from a different server: $ $BRPDIR/mailsend -f bradr@ryankids.com -starttls -smtp smtp.elasticemail.co>
+++++++++++ attach: 'SA330P_20120816103135.PDF,application/pdf,a'
file: SA330P_20120816103135.pdf
Error: smtp.c (712) - Could not open file for SA330P_20120816103135.pdf reading) Error: smtp.c (780) - Could not encode attachment SA330P_20120816103135.pdf
Error: smtp.c (895) - failed to send attachment SA330P_20120816103135.pdf

Could not send mail

You can see in the later example, the .PDF extension was passed in as uppercase and by the time it came to open the file, it has been changed to lowercase.

Do you have any suggestions?

muquit commented 5 years ago

I can not seem to reproduce it. But it is possible there is bug in parsing the -attach line. Instead of comma separated, would try like following?

-mime-type 'application/pdf' -disposition 'attach' -attach 'SA330P_20120816103135.PDF'

Thanks.

glewis64 commented 5 years ago

Ran as requested … same result.

$ type 'application/pdf' -disposition 'attachment' -attach 'SA330P_2012081610* +++++++++++ attach: 'SA330P_20120816103135.PDF' file: SA330P_20120816103135.pdf Error: smtp.c (712) - Could not open file for SA330P_20120816103135.pdf reading) Error: smtp.c (780) - Could not encode attachment SA330P_20120816103135.pdf Error: smtp.c (895) - failed to send attachment SA330P_20120816103135.pdf

Could not send mail

I’m trying to follow the code to see where to place more debug code.

Thanks so much for your help. Gayle

From: muquit [mailto:notifications@github.com] Sent: Friday, August 24, 2018 1:51 PM To: muquit/mailsend mailsend@noreply.github.com Cc: Gayle Lewis glewis@agtrax.com; Author author@noreply.github.com Subject: Re: [muquit/mailsend] AIX Switching attachment extensions to lowercase (#140)

I can not seem to reproduce it. But it is possible there is bug in parsing the -attach line. Instead of comma separated, would try like following?

-mime-type 'application/pdf' -disposition 'attach' -attach 'SA330P_20120816103135.PDF'

Thanks.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/muquit/mailsend/issues/140#issuecomment-415849801, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AogdioBYxbMRoYht20mQ6joOyT_a9o46ks5uUEsXgaJpZM4WJ6LS.

muquit commented 5 years ago

ok I was able to reproduce it, I will try to fix it over the weekend.

glewis64 commented 5 years ago

I was just getting ready to send you an email. I debugged it down to the get_mime_type routine in utils.c

If the application found the attachment is a binary, this routine got called and when it lowered the case of the extension it actually lowered the case of the file_path sent into the routine as well.

I was able to reproduce it on my compile server as well. The PDF I was using on my compile server, it didn’t think it was a binary file so it never called get_mime_type.

Is this what you’re seeing as well?

Thanks so much for your help. Gayle

From: muquit [mailto:notifications@github.com] Sent: Friday, August 24, 2018 3:42 PM To: muquit/mailsend mailsend@noreply.github.com Cc: Gayle Lewis glewis@agtrax.com; Author author@noreply.github.com Subject: Re: [muquit/mailsend] AIX Switching attachment extensions to lowercase (#140)

ok I was able to reproduce it, I will try to fix it over the weekend.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/muquit/mailsend/issues/140#issuecomment-415876939, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AogdihgaDaEUUg_SthKl1dj1xIdr2kd1ks5uUGUpgaJpZM4WJ6LS.

muquit commented 5 years ago

Yes it was the root cause. Instead of allocating memory before determining extension and lower casing it, it was modifying the passed string, which was the path of the attachment. Good find! Thanks

glewis64 commented 5 years ago

Good morning,

Any luck in getting this fixed?

Thanks, Gayle From: muquit [mailto:notifications@github.com] Sent: Friday, August 24, 2018 3:42 PM To: muquit/mailsend mailsend@noreply.github.com Cc: Gayle Lewis glewis@agtrax.com; Author author@noreply.github.com Subject: Re: [muquit/mailsend] AIX Switching attachment extensions to lowercase (#140)

ok I was able to reproduce it, I will try to fix it over the weekend.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/muquit/mailsend/issues/140#issuecomment-415876939, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AogdihgaDaEUUg_SthKl1dj1xIdr2kd1ks5uUGUpgaJpZM4WJ6LS.

muquit commented 5 years ago

Please try the trunk. Thanks.