Rt_client ruby: Issue with attachments in a multipart email

Hello,

It seems that if a user sends an HTML formatted email (multipart) with
an attachment. RT_Client does not dig deep enough to get to the
attachment when calling rt.attachments. The multipart part is unamed
and rt_client does not look into it.

Before I try other libraries:

  • From what I see on their wiki, roart does not do attachments, is that correct?
  • Is there a similar problem with RT::Client::REST?

Thanks,
Thierry

Sorry, there is a bug, but not the one I thought it was.

Calling ‘by hand’ the REST interface does show the attachment ID. My
issue is with a character in the filename breaking rt_client parsing,
I think.

My attachment file name has spaces, commas and dots. I am quite sure
that the problem is somewhere here:
m=v.match(/(\d+):\s+(.?)\s+((.?)\s+/\s+(.*?))/)

I will report back later.
Thierry

Ok, 2nd correction. sorry.

The error was not with the multipart, and not with the regular
expression. It is in the line:

 list = th["attachments"].to_s.split(",")

It is splitting the lines based on the presence of commas. My
filename contains a comma…

Thierry

Send me a patch. I’m the author of that gem. Or if you need help, send me your email as a text file and I’ll look into it.

As far as I know roart does not do attachments at all, but that may have changed. I’m not involved with that gem – it was made for Rails programmers who are familiar with ActiveRecord, whereas rt-client was made (by me) for a more procedural approach. As I’m not a rails guy, that paradigm never occurred to me.

In fact, I think I have some updates on my dev box that I haven’t pushed to gemcutter, but I’m sure I haven’t addressed your issue.On Oct 24, 2010, at 8:14 PM, Thierry Thelliez thierry.thelliez.tech@gmail.com wrote:

Ok, 2nd correction. sorry.

The error was not with the multipart, and not with the regular
expression. It is in the line:

list = th["attachments"].to_s.split(",")

It is splitting the lines based on the presence of commas. My
filename contains a comma…

Thierry

So, I went ahead and set up a test case with an RT instance here and made an attachment with a comma in the filename to play with. There is now an updated rt-client on rubygems.org, version 0.3.3 that addresses the issue and should work. Let me know if you have any problems.

There are probably additional methods in the API that you haven’t seen before as well, read the docs. I don’t think I’ve broken backward compatibility on this gem ever, but you never know.

Tom Lahti, SCMDBA, LPIC-1, CLA
BIT LLC
425-251-0833 x 117On Oct 24, 2010, at 9:00 PM, Tom Lahti wrote:

Send me a patch. I’m the author of that gem. Or if you need help, send me your email as a text file and I’ll look into it.

As far as I know roart does not do attachments at all, but that may have changed. I’m not involved with that gem – it was made for Rails programmers who are familiar with ActiveRecord, whereas rt-client was made (by me) for a more procedural approach. As I’m not a rails guy, that paradigm never occurred to me.

In fact, I think I have some updates on my dev box that I haven’t pushed to gemcutter, but I’m sure I haven’t addressed your issue.

On Oct 24, 2010, at 8:14 PM, Thierry Thelliez thierry.thelliez.tech@gmail.com wrote:

Ok, 2nd correction. sorry.

The error was not with the multipart, and not with the regular
expression. It is in the line:

list = th[“attachments”].to_s.split(",")

It is splitting the lines based on the presence of commas. My
filename contains a comma…

Thierry

Tom,

Thanks you so much. I was finally getting to it when I saw your email.
I tried your fix and it works for me. More testing later.

Thierry

Tom,

Yesterday I encountered another similar issue.

Looking at the code, I see that the attachments parsing (in
rt_client0.3.7) relies on a pattern assuming ‘),’ as a separator.

client.rb line 608:
pattern = /(\d+:\s.*?)),/

But one of ours users uploaded a file with ‘),’ in the file name…

Also the above pattern skips the last attachment in the list.
Although I think that this is always an ‘unnamed’ one. One of the
problems is that the TMail::Mail.parse scraps the line breaks. So this
makes it difficult to write a reliable regular expression. So ideally
the code should be reorganized to parse ‘resp’ without the TMail
parsing, I think.

For this morning, I just made the regular expression a lot less likely
to hit a false positive:

pattern = /\d+:\s+.*?\s+\(.*?\/.*?\s+\/\s+.*?[bkm]\)(,\s|$)/

Not perfect, but better for now.

(BTW, above I try to match a ‘b’ or a ‘k’, I am assuming that an 'm’
could happen, not sure)

Thierry ThelliezOn Tue, Oct 26, 2010 at 3:59 PM, Thierry Thelliez thierry.thelliez.tech@gmail.com wrote:

Tom,

Thanks you so much. I was finally getting to it when I saw your email.
I tried your fix and it works for me. More testing later.

Thierry