コード例 #1
0
ファイル: webmessage_tests.py プロジェクト: lbjay/cds-invenio
    def test_simple_quoting(self):
        """webmessage - test quoting simple message"""
        text = """Dear romeo
I received your mail
>>Would you like to come with me to the restaurant?
Of course!
>>>>When could we get together?
Reply to my question please.
    see you..."""
        expected_text = """Dear romeo<br/>
I received your mail<br/>
<div class="commentbox">
\tWould you like to come with me to the restaurant?<br/>
</div>
Of course!<br/>
<div class="commentbox">
\t<div class="commentbox">
\t\tWhen could we get together?<br/>
\t</div>
</div>
Reply to my question please.<br/>
    see you...<br/>
"""
        res =  webmessage_mailutils.email_quoted_txt2html(text,
                                                          tabs_before=0,
                                                          indent_txt='>>',
                                                          linebreak_txt="\n",
                                                          indent_html=('<div class="commentbox">', "</div>"),
                                                          linebreak_html='<br/>')
        self.assertEqual(res, expected_text)
コード例 #2
0
    def test_simple_quoting_per_line(self):
        """webmessage - test quoting simple message (HTML, per line)"""
        text = """Dear romeo
I received your mail
>>Would you like to come with me to the restaurant?
>>I discovered a really nice one.
Of course!
>>>>When could we get together?
Reply to my question please.
    see you..."""
        expected_text = """Dear romeo&nbsp;<br/>
I received your mail&nbsp;<br/>
<blockquote><div>Would you like to come with me to the restaurant?&nbsp;</div></blockquote>&nbsp;<br/>
<blockquote><div>I discovered a really nice one.&nbsp;</div></blockquote>&nbsp;<br/>
Of course!&nbsp;<br/>
<blockquote><div><blockquote><div>When could we get together?&nbsp;</div></blockquote>&nbsp;</div></blockquote>&nbsp;<br/>
Reply to my question please.&nbsp;<br/>
    see you...&nbsp;<br/>
"""
        res = webmessage_mailutils.email_quoted_txt2html(
            text,
            tabs_before=0,
            indent_txt='>>',
            linebreak_txt="\n",
            indent_html=('<blockquote><div>', '&nbsp;</div></blockquote>'),
            linebreak_html="&nbsp;<br/>",
            indent_block=False)
        self.assertEqual(res, expected_text)
コード例 #3
0
    def test_simple_quoting_per_block(self):
        """webmessage - test quoting simple message (HTML, per block)"""
        text = """Dear romeo
I received your mail
>>Would you like to come with me to the restaurant?
Of course!
>>>>When could we get together?
Reply to my question please.
    see you..."""
        expected_text = """Dear romeo<br/>
I received your mail<br/>
<div class="commentbox">
\tWould you like to come with me to the restaurant?<br/>
</div>
Of course!<br/>
<div class="commentbox">
\t<div class="commentbox">
\t\tWhen could we get together?<br/>
\t</div>
</div>
Reply to my question please.<br/>
    see you...<br/>
"""
        res = webmessage_mailutils.email_quoted_txt2html(
            text,
            tabs_before=0,
            indent_txt='>>',
            linebreak_txt="\n",
            indent_html=('<div class="commentbox">', "</div>"),
            linebreak_html='<br/>')
        self.assertEqual(res, expected_text)
コード例 #4
0
    def test_simple_quoting_per_line(self):
        """webmessage - test quoting simple message (HTML, per line)"""
        text = """Dear romeo
I received your mail
>>Would you like to come with me to the restaurant?
>>I discovered a really nice one.
Of course!
>>>>When could we get together?
Reply to my question please.
    see you..."""
        expected_text = """Dear romeo&nbsp;<br/>
I received your mail&nbsp;<br/>
<blockquote><div>Would you like to come with me to the restaurant?&nbsp;</div></blockquote>&nbsp;<br/>
<blockquote><div>I discovered a really nice one.&nbsp;</div></blockquote>&nbsp;<br/>
Of course!&nbsp;<br/>
<blockquote><div><blockquote><div>When could we get together?&nbsp;</div></blockquote>&nbsp;</div></blockquote>&nbsp;<br/>
Reply to my question please.&nbsp;<br/>
    see you...&nbsp;<br/>
"""
        res =  webmessage_mailutils.email_quoted_txt2html(text,
                                                          tabs_before=0,
                                                          indent_txt='>>',
                                                          linebreak_txt="\n",
                                                          indent_html=('<blockquote><div>', '&nbsp;</div></blockquote>'),
                                                          linebreak_html="&nbsp;<br/>",
                                                          indent_block=False)
        self.assertEqual(res, expected_text)
コード例 #5
0
    def tmpl_display_msg(self,
                         msg_id="",
                         msg_from_id="",
                         msg_from_nickname="",
                         msg_sent_to="",
                         msg_sent_to_group="",
                         msg_subject="",
                         msg_body="",
                         msg_sent_date="",
                         msg_received_date=datetext_default,
                         ln=CFG_SITE_LANG):
        """
        Displays a given message
        @param msg_id: id of the message
        @param msg_from_id: id of user who sent the message
        @param msg_from_nickname: nickname of the user who sent the message
        @param msg_sent_to: list of users who received the message
                            (comma separated string)
        @param msg_sent_to_group: list of groups who received the message
                                  (comma separated string)
        @param msg_subject: subject of the message
        @param msg_body: body of the message
        @param msg_sent_date: date at which the message was sent
        @param msg_received_date: date at which the message had to be received
                                  (if this argument != 0000-00-00 => reminder
        @param ln: language of the page
        @return: the message in HTML format
        """

        # load the right message language
        _ = gettext_set_language(ln)

        sent_to_link = ''
        tos = msg_sent_to.split(CFG_WEBMESSAGE_SEPARATOR)
        if (tos):
            for to in tos[0:-1]:
                to_display = to
                if to.isdigit():
                    (dummy, to, to_display) = get_user_info(int(to), ln)
                sent_to_link += create_html_link(CFG_SITE_URL + '/yourmessages/write',
                                                 {'msg_to': to, 'ln': ln},
                                                 escape_html(to_display))
                sent_to_link += CFG_WEBMESSAGE_SEPARATOR
            to_display = tos[-1]
            to = tos[-1]
            if to.isdigit():
                (dummy, to, to_display) = get_user_info(int(to), ln)
            sent_to_link += create_html_link(CFG_SITE_URL + '/yourmessages/write',
                                             {'msg_to': to, 'ln': ln},
                                             escape_html(to_display))
        group_to_link = ""
        groups = msg_sent_to_group.split(CFG_WEBMESSAGE_SEPARATOR)
        if (groups):
            for group in groups[0:-1]:
                group_to_link += create_html_link(
                                    CFG_SITE_URL + '/yourmessages/write',
                                    {'msg_to_group': group, 'ln': ln},
                                    escape_html(group))
                group_to_link += CFG_WEBMESSAGE_SEPARATOR
            group_to_link += create_html_link(
                                CFG_SITE_URL + '/yourmessages/write',
                                {'msg_to_group': groups[-1], 'ln': ln},
                                escape_html(groups[-1]))
        # format the msg so that the '>>' chars give vertical lines
        final_body = email_quoted_txt2html(msg_body)

        out = """
<table class="mailbox" style="width: 70%%;">
  <thead class="mailboxheader">
    <tr>
      <td class="inboxheader" colspan="2">
        <table class="messageheader">
          <tr>
            <td class="mailboxlabel">%(from_label)s</td>
            <td>%(from_link)s</td>
          </tr>
          <tr>
            <td class="mailboxlabel">%(subject_label)s</td>
            <td style="width: 100%%;">%(subject)s</td>
          </tr>
          <tr>
            <td class="mailboxlabel">%(sent_label)s</td>
            <td>%(sent_date)s</td>
          </tr>"""
        if (msg_received_date != datetext_default):
            out += """
          <tr>
            <td class="mailboxlabel">%(received_label)s</td>
            <td>%(received_date)s</td>
          </tr>"""
        out += """
          <tr>
            <td class="mailboxlabel">%(sent_to_label)s</td>
            <td>%(sent_to)s</td>
          </tr>"""
        if (msg_sent_to_group != ""):
            out += """
          <tr>
            <td class="mailboxlabel">%(groups_label)s</td>
            <td>%(sent_to_group)s</td>
          </tr>"""
        out += """
        </table>
      </td>
    </tr>
  </thead>
  <tfoot>
    <tr>
      <td></td>
      <td></td>
    </tr>
  </tfoot>
  <tbody class="mailboxbody">
    <tr class="mailboxrecord">
      <td colspan="2">%(body)s</td>
    </tr>
    <tr class="mailboxfooter">
      <td>
        <form name="reply" action="%(reply_url)s" method="post">
          <input class="formbutton" name="reply" value="%(reply_but_label)s" type="submit" />
        </form>
      </td>
      <td>
        <form name="deletemsg" action="%(delete_url)s" method="post">
          <input class="formbutton" name="delete" value="%(delete_but_label)s" type="submit" />
        </form>
      </td>
    </tr>
  </tbody>
</table>
        """
        if msg_from_nickname:
            msg_from_display = msg_from_nickname
        else:
            msg_from_display = get_user_info(msg_from_id, ln)[2]
            msg_from_nickname = msg_from_id

        return out % {'from_link': create_html_link(
                                        CFG_SITE_URL + '/yourmessages/write',
                                        {'msg_to': msg_from_nickname,
                                         'ln': ln},
                                        msg_from_display),
                     'reply_url': create_url(CFG_SITE_URL + '/yourmessages/write',
                                             {'msg_reply_id': msg_id,
                                             'ln':  ln}),
                     'delete_url': create_url(CFG_SITE_URL + '/yourmessages/delete',
                                             {'msgid': msg_id,
                                             'ln':  ln}),
                     'sent_date' : convert_datetext_to_dategui(msg_sent_date, ln),
                     'received_date': convert_datetext_to_dategui(msg_received_date, ln),
                     'sent_to': sent_to_link,
                     'sent_to_group': group_to_link,
                     'subject' : msg_subject,
                     'body' : final_body,
                     'reply_to': msg_from_id,
                     'ln': ln,
                     'from_label':_("From:"),
                     'subject_label':_("Subject:"),
                     'sent_label': _("Sent on:"),
                     'received_label':_("Received on:"),
                     'sent_to_label': _("Sent to:"),
                     'groups_label': _("Sent to groups:"),
                     'reply_but_label':_("REPLY"),
                     'delete_but_label': _("DELETE")}
コード例 #6
0
    def tmpl_display_msg(self,
                         msg_id="",
                         msg_from_id="",
                         msg_from_nickname="",
                         msg_sent_to="",
                         msg_sent_to_group="",
                         msg_subject="",
                         msg_body="",
                         msg_sent_date="",
                         msg_received_date=datetext_default,
                         ln=CFG_SITE_LANG):
        """
        Displays a given message
        @param msg_id: id of the message
        @param msg_from_id: id of user who sent the message
        @param msg_from_nickname: nickname of the user who sent the message
        @param msg_sent_to: list of users who received the message
                            (comma separated string)
        @param msg_sent_to_group: list of groups who received the message
                                  (comma separated string)
        @param msg_subject: subject of the message
        @param msg_body: body of the message
        @param msg_sent_date: date at which the message was sent
        @param msg_received_date: date at which the message had to be received
                                  (if this argument != 0000-00-00 => reminder
        @param ln: language of the page
        @return: the message in HTML format
        """

        # load the right message language
        _ = gettext_set_language(ln)

        sent_to_link = ''
        tos = msg_sent_to.split(CFG_WEBMESSAGE_SEPARATOR)
        if (tos):
            for to in tos[0:-1]:
                to_display = to
                if to.isdigit():
                    (dummy, to, to_display) = get_user_info(int(to), ln)
                sent_to_link += create_html_link(
                    CFG_SITE_URL + '/yourmessages/write', {
                        'msg_to': to,
                        'ln': ln
                    }, escape_html(to_display))
                sent_to_link += CFG_WEBMESSAGE_SEPARATOR
            to_display = tos[-1]
            to = tos[-1]
            if to.isdigit():
                (dummy, to, to_display) = get_user_info(int(to), ln)
            sent_to_link += create_html_link(
                CFG_SITE_URL + '/yourmessages/write', {
                    'msg_to': to,
                    'ln': ln
                }, escape_html(to_display))
        group_to_link = ""
        groups = msg_sent_to_group.split(CFG_WEBMESSAGE_SEPARATOR)
        if (groups):
            for group in groups[0:-1]:
                group_to_link += create_html_link(
                    CFG_SITE_URL + '/yourmessages/write', {
                        'msg_to_group': group,
                        'ln': ln
                    }, escape_html(group))
                group_to_link += CFG_WEBMESSAGE_SEPARATOR
            group_to_link += create_html_link(
                CFG_SITE_URL + '/yourmessages/write', {
                    'msg_to_group': groups[-1],
                    'ln': ln
                }, escape_html(groups[-1]))
        # format the msg so that the '>>' chars give vertical lines
        final_body = email_quoted_txt2html(msg_body)

        out = """
<table class="mailbox" style="width: 70%%;">
  <thead class="mailboxheader">
    <tr>
      <td class="inboxheader" colspan="2">
        <table class="messageheader">
          <tr>
            <td class="mailboxlabel">%(from_label)s</td>
            <td>%(from_link)s</td>
          </tr>
          <tr>
            <td class="mailboxlabel">%(subject_label)s</td>
            <td style="width: 100%%;">%(subject)s</td>
          </tr>
          <tr>
            <td class="mailboxlabel">%(sent_label)s</td>
            <td>%(sent_date)s</td>
          </tr>"""
        if (msg_received_date != datetext_default):
            out += """
          <tr>
            <td class="mailboxlabel">%(received_label)s</td>
            <td>%(received_date)s</td>
          </tr>"""
        out += """
          <tr>
            <td class="mailboxlabel">%(sent_to_label)s</td>
            <td>%(sent_to)s</td>
          </tr>"""
        if (msg_sent_to_group != ""):
            out += """
          <tr>
            <td class="mailboxlabel">%(groups_label)s</td>
            <td>%(sent_to_group)s</td>
          </tr>"""
        out += """
        </table>
      </td>
    </tr>
  </thead>
  <tfoot>
    <tr>
      <td></td>
      <td></td>
    </tr>
  </tfoot>
  <tbody class="mailboxbody">
    <tr class="mailboxrecord">
      <td colspan="2">%(body)s</td>
    </tr>
    <tr class="mailboxfooter">
      <td>
        <form name="reply" action="%(reply_url)s" method="post">
          <input class="formbutton" name="reply" value="%(reply_but_label)s" type="submit" />
        </form>
      </td>
      <td>
        <form name="deletemsg" action="%(delete_url)s" method="post">
          <input class="formbutton" name="delete" value="%(delete_but_label)s" type="submit" />
        </form>
      </td>
    </tr>
  </tbody>
</table>
        """
        if msg_from_nickname:
            msg_from_display = msg_from_nickname
        else:
            msg_from_display = get_user_info(msg_from_id, ln)[2]
            msg_from_nickname = msg_from_id

        return out % {
            'from_link':
            create_html_link(CFG_SITE_URL + '/yourmessages/write', {
                'msg_to': msg_from_nickname,
                'ln': ln
            }, msg_from_display),
            'reply_url':
            create_url(CFG_SITE_URL + '/yourmessages/write', {
                'msg_reply_id': msg_id,
                'ln': ln
            }),
            'delete_url':
            create_url(CFG_SITE_URL + '/yourmessages/delete', {
                'msgid': msg_id,
                'ln': ln
            }),
            'sent_date':
            convert_datetext_to_dategui(msg_sent_date, ln),
            'received_date':
            convert_datetext_to_dategui(msg_received_date, ln),
            'sent_to':
            sent_to_link,
            'sent_to_group':
            group_to_link,
            'subject':
            msg_subject,
            'body':
            final_body,
            'reply_to':
            msg_from_id,
            'ln':
            ln,
            'from_label':
            _("From:"),
            'subject_label':
            _("Subject:"),
            'sent_label':
            _("Sent on:"),
            'received_label':
            _("Received on:"),
            'sent_to_label':
            _("Sent to:"),
            'groups_label':
            _("Sent to groups:"),
            'reply_but_label':
            _("REPLY"),
            'delete_but_label':
            _("DELETE")
        }
コード例 #7
0
ファイル: jinja2utils.py プロジェクト: pombredanne/webdeposit
 def _quoted_txt2html(*args, **kwargs):
     return email_quoted_txt2html(*args, **kwargs)