Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shared (inherited) clean_FOO methods for common message fields #17

Open
hugorodgerbrown opened this issue Nov 3, 2014 · 0 comments
Open

Comments

@hugorodgerbrown
Copy link
Contributor

Each backend service has a unique implementation that extracts the relevant data as part of their implementation of the parse method. In reality, although each backend is unique, they are all extracting strings from an HTTP request object, and there are some shared rules around how to treat this data - e.g. the various email RFCs.

Proposed solution is to have a set of clean_FOO methods in the base RequestParser class that the the implementation can call that implement these basic rules.

e.g.

import email

class RequestParser()
    def clean_to(self, value):
        """Parse string and return list of (name, <address>) tuples."""
        return email.utils.getaddresses(value)

    def parse(self, request):
        raise NotImplementedError(u"Must be implemented by inheriting class.")

# and in the implementation
class MyRequestParser(RequestParser):
    def parse(self, request):
        to = self.clean_to(request.POST.get('recipient')
        [...]

Suggested methods:

  • clean_sender - parse email address
  • clean_recipients - parse email addresses
  • clean_html_message - parse HTML, mark safe,
  • clean_txt_message - parse text, convert to UTF-8 encoded unicode
  • clean_subject - parse subject, convert to UTF-8 encoded unicode
  • clean_cc_recipients - parse email addresses
  • clean_bcc_recipients - parse email addresses
  • clean_attachments - handle file type restrictions, max/min sizes etc.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant