Download & Extend

How to Strip quoted messages and other unwanted text from body

Project:Listhandler
Version:master
Component:Documentation
Category:task
Priority:major
Assigned:Unassigned
Status:active

Issue Summary

Does anyone know of a way to automatically remove the quoted message that shows in a users reply at the bottom of the reply?

Any help would be appreciated.

Comments

#1

Do you mean remove itfrom messagges imported in the forum?
To get this goal i use http://drupal.org/project/customfilter.
After installing it, you have to create a custom content filter with a regular expression that matches and delete the mail forward pattern (or any other pattern you want).
Then set that filter as default input format in the mailhandler mailbox setting,

#2

I would like to do this also. I have tried using the custom filter but mind is being blown by the regex stuff.

The quoted messages appears in the forum on my site as

On Tue, 12 Feb 2008 13:28:53 +1100, Matthew Young
wrote:
> Hi all,
>
> Just setting up and testing the new websites integration of mailing
> list into the forum. The website should be ready to go live soon.
>
> Regards,
> Matt Young.
> _______________________________________________
> OpenVPMs User Mailing List
> users@lists.openvpms.org
> http://lists.openvpms.org/mailman/listinfo/users

Should I be using a regex to identify the > at the start of the lines or use the starting and ending bits of the quote and delete anything in between.

Any chance of sharing your custom filter settings for this with us samuelet or anyone else?

#3

I don't delete the whole quoting but I prefer to leave the quoting header with this regex

pattern:
/(\>\s{0,3}.*\n\>\s{0,3}.*\n)+/

replace:
> ....

This helps to follow the reply workflow in a flat list forum.
The regex was on-the-fly made and looking at it now it seems not perfect ,but it works.

I also delete mailman signature with a regex like this (not tested for your case):
pattern:
/\_{20,}.*(\n.*\n.*\n.*\/OpenVPMs|(\n|.).*\<(a|A).*\/(a|A)\>)/

replace:
(empty)

This regex should be applied with more weight than previous.

I've others regex but they are modelled after italian language so they could not work correctly for you.

Pay attention that custom filter caches its filter and you could need to reapply it also from "Input format" page.
Hope it could help to create your own.

#4

Customfilter is discontinued and has no d6 port. I'm trying to figure out a way to strip out comments with flexifilter, but am having a hell of a time. If anyone has figured out how to wrangle flexifilter, let me know!

#5

@samuelet:
For each mailbox, you can set the Signature identifier in Mailhandler.
Go to Content management -> Mailhandler -> <Mailbox> -> Signature separator:

#6

Title:A Question about quoted messages in body» Strip quoted messages and other unwanted text from body
Version:5.x-1.x-dev» master

#7

Title:Strip quoted messages and other unwanted text from body» How to Strip quoted messages and other unwanted text from body

#8

Component:Miscellaneous» Documentation
Category:support request» task

The task to perform consists of:

  • Add to listhandler additional documentation advising modules that can be used to realize this
  • Some clear examples of how to setup those modules to perform the outcome wanted
  • #9

    Priority:normal» major

    Changed the priority since it is clear a lot of users actually want such a possibility

    #10

    Since subdian on April 28, 2009 at 12:20pm nicely coded something and added it to the duplicate issue #446328: Strip quoted emails in replies we'll add it here. It may not really the flexible solution we are looking for, however for it may come in handy to determine a solution.

    While I'm not sure how to make a proper patch file, here's a diff file with my changes:

    < // $Id: listhandler.module,v 1.75.2.13 2008/10/27 20:10:29 philipnet Exp $
    ---
    > // $Id: listhandler.module,v 1.75.2.12 2008/07/26 16:21:15 philipnet Exp $
    83,91d82
    <
    <   $form['listhandler_strip_body'] = array(
    <     '#type' => 'textfield',
    <     '#title' => t('Strip body from'),
    <     '#default_value' => variable_get('listhandler_strip_body', '/(On .*? wrote)|(_{10,}\s*From:)|((>\s*){0,1}-{5,}\s*Original Message\s*-{5,})/'),
    <     '#size' => 50,
    <     '#maxlength' => 1024,
    <     '#description' => t("A comma delimited regex from which the body of messages should be discarded. Useful for deleting unwanted reply emails"));
    <
    161,162d151
    <   variable_set('listhandler_strip_body', $form_values['listhandler_strip_body']);
    <
    190,192c179,183
    <           $node->subject = $node->title;
    <           $node->comment = $node->body;
    <           listhandler_send_mail((array) $node);
    ---
    >           if(!spam_content_filter('forum', $node->nid, $node->title, $node->body)) {
    >             $node->subject = $node->title;
    >             $node->comment = $node->body;
    >             listhandler_send_mail((array) $node);
    >           }
    239,240c230,232
    <
    <       listhandler_send_mail($edit);
    ---
    >       if(!spam_content_filter('comment', $edit['cid'], $edit['subject'], $edit['comment'])) {
    >         listhandler_send_mail($edit);
    >       }
    251,259c243
    <
    <   if (!$user->uid) {
    <     $edit['name'] = variable_get('anonymous', 'Anonymous');
    <     $edit['mail'] = variable_get('listhandler_from', '');
    <   }
    <   else {
    <     $edit["name"] = $user->name;
    <     $edit["mail"] = $user->mail;
    <   }
    ---
    >
    296a281,294
    >   // Fill the user email, check if subscribed
    >   if (!$user->uid) {
    >     $edit['name'] = variable_get('anonymous', 'Anonymous');
    >     $edit['mail'] = variable_get('listhandler_from', '');
    >   }
    >   else if(!_listhandler_user_subscribed($mboxen[0][1], $user->mail)) {
    >     $edit['name'] = variable_get('anonymous', 'Anonymous');
    >     $edit['mail'] = $user->name . ' <' . variable_get('listhandler_from', '').'>';
    >   }
    >   else {
    >     $edit["name"] = $user->name;
    >     $edit["mail"] = $user->mail;
    >   }
    >
    437,443d434
    <
    <       //Remove body from regex
    <       $strip_body_regex = variable_get('listhandler_strip_body', '');
    <       $body = preg_split($strip_body_regex, $node->body);
    <
    <       $node->body = $body[0];
    <
    581c572
    <       $message  .= "Content-Type:$file->filemime;\n\tname=\"$file->filename\"\n";
    ---
    >       $message  .= "Content-Type:$file->filemime;\n\tname=$file->filename\n";
    583c574
    <       $message  .= "Content-Disposition: attachment;\n\tfilename=\"$file->filename\"\n\n";
    ---
    >       $message  .= "Content-Disposition: attachment;\n\tfilename=$file->filename\n\n";
    627a619,631
    >
    > function _listhandler_user_subscribed($list_mail, $user_mail) {
    >   //Get the mail up to the @, add -request to it
    >   $list_name = substr($list_mail, 0, strpos($list_mail, '@'));
    >   $list_req = $list_name . '-request'.substr($list_mail, strpos($list_mail, '@'));
    >
    >   //Match mailman users table
    > $sql = "SELECT lstatus FROM {mailman_users} mu LEFT JOIN {mailman_lists} ml on mu.lid=ml.lid WHERE mu.lmail='".$user_mail."' AND ml.command='".$list_req."' AND mu.lstatus<>0";
    >   $result = db_query("SELECT lstatus FROM {mailman_users} mu LEFT JOIN {mailman_lists} ml on mu.lid=ml.lid WHERE mu.lmail='".$user_mail."' AND ml.command='".$list_req."' AND mu.lstatus<>0");
    >   if(db_num_rows($result)>0) return true;
    >   else return false;
    >
    > }
    nobody click here