Forum OpenACS Development: Attachments and acs-mail-lite

Collapse
Posted by Ryan Gallimore on
acs-mail-lite uses the cr_items.name for the filename of the attachment.

When content::item::upload_file is used, the name is rewritten without an extension. This often confuses mail clients. However, cr_revisions.title retains the original filename.

Any complaints if I change the attachment filename to use cr_revisions.title instead of cr_items.name?

Collapse
Posted by Emmanuelle Raffenne on
Hi Ryan,

If you change the attachment to be "title" and the file actually has a title or doesn't have any (blank), then the attachment tagging won't work correctly and the file will be sent with no name.

I think it's upload_file that needs to be fixed, there's no reason to store the name of the item without extension. In 5.6 the line that removes the extension of the filename to fill the title is commented. What openacs version are you using?

Collapse
Posted by Ryan Gallimore on
Hi Emma,

Good point regarding a null title. I am using 5.6.

The name is sanitized by util_text_to_url in upload_file.

I would suggest changing the regexp to allow for a period:

# substitute all non-word characters
regsub -all {([^a-z0-9\.])+} $text $replacement text

This sets the name with a proper extension unless there are name conflicts, in which case file.pdf becomes file.pdf_2.

Collapse
Posted by Ryan Gallimore on
Emma, do you think it is reasonable to include the extension period and alter the unique numbering from something like file.pdf_2 to file-2.pdf?

This would solve the problem of opening attachments in some e-mail clients.

Collapse
Posted by Emmanuelle Raffenne on
Hi Ryan,

It's better than modifying the extension IMO.

Collapse
Posted by Dave Bauer on
Yes, you need to split the filename and extension, then generate the unique filenames then put the extension back on.

text_to_url doesn't care about extensions since it just generates a unique URL which doesn' need one, so reusing for this purpose requires some extra logic.

Collapse
Posted by Tory Pitt on
I find this post very informative. Thank you very much.