# Infinite loop in email\_reply\_trimmer

**URL:** https://meta.discourse.org/t/infinite-loop-in-email-reply-trimmer/69427
**Category:** Development
**Created:** [September 5, 2017, 8:06pm UTC](https://meta.discourse.org/t/infinite-loop-in-email-reply-trimmer/69427 "2017-09-05T20:06:55Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 5, 2017, 8:06pm UTC](https://meta.discourse.org/t/infinite-loop-in-email-reply-trimmer/69427/1 "2017-09-05T20:06:55Z")

</div>

this is a 🐛, but I think only developers will care about it. There’s an infinite loop in one of these replacements. I found it while running the `nabble` importer. I banged at it a bit before just commenting it out to solve my immediate problem.

It looks like @zogstrip understands this. It seems that sometimes 183 gets stuck. I was wondering why these 170K messages need an entire holiday weekend to import.

> <https://github.com/discourse/email_reply_trimmer/blob/main/lib/email_reply_trimmer.rb#L175>

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [September 6, 2017, 12:02pm UTC](https://meta.discourse.org/t/infinite-loop-in-email-reply-trimmer/69427/2 "2017-09-06T12:02:49Z")

</div>

Do you have an example that fails?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 6, 2017, 2:03pm UTC](https://meta.discourse.org/t/infinite-loop-in-email-reply-trimmer/69427/3 "2017-09-06T14:03:47Z")

</div>

I just assumed that it’d be self evident, because those regexes are so simple.

Yes. I did get the script to spit out the errant one,but by the time I was sure this was the problem it was gone. I’ll try to run it again Real Soon Now.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 12, 2017, 4:27pm UTC](https://meta.discourse.org/t/infinite-loop-in-email-reply-trimmer/69427/5 "2017-09-12T16:27:46Z")

</div>

And now it seems that maybe an upgrade made that problem go away, but now Nabble seems not to import any messages that have been emailed in (as opposed to created in the Nabble web interface).

If there’s some easy way to decode a MIME-encoded email, I’d love to know about it.

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [September 12, 2017, 4:31pm UTC](https://meta.discourse.org/t/infinite-loop-in-email-reply-trimmer/69427/6 "2017-09-12T16:31:01Z")

</div>

Not sure about the “MIME-encoded email”, but at least I can reproduce the problem in `EmailReplyTrimmer`. ~~I’ll fix it tomorrow.~~ This is now fixed.

> <https://github.com/discourse/email_reply_trimmer/pull/12>
>
> The \`\[\\s\\S\]\` was causing problems (the matching could take forever) when none of… the backreferenced words (e.g. \`Am|schrieben\\sSie\`) was found.
> 
> I replaced it with \`.\` and the \`/m\` option and added a test.
> 
> @ZogStriP Can we release a new version if this is fine?

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 18, 2017, 9:47pm UTC](https://meta.discourse.org/t/infinite-loop-in-email-reply-trimmer/69427/7 "2017-09-18T21:47:19Z")

</div>

This seems to improve things, though I still have messages that are taking \>30 seconds to parse a message. They all look Really Long (\> 500K bytes?).

Do you want them?

---

<div class="post-metadata">

### Author: ![gerhard](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gerhard/32/119479_2.png) [@gerhard](https://meta.discourse.org/u/gerhard)
#### Post date: [September 18, 2017, 10:01pm UTC](https://meta.discourse.org/t/infinite-loop-in-email-reply-trimmer/69427/8 "2017-09-18T22:01:37Z")

</div>

Sure, send me a few of those. I’ll take a look.

---

<div class="post-metadata">

### Author: ![pfaffman](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pfaffman/32/120154_2.png) [@pfaffman](https://meta.discourse.org/u/pfaffman)
#### Post date: [September 23, 2017, 10:55pm UTC](https://meta.discourse.org/t/infinite-loop-in-email-reply-trimmer/69427/9 "2017-09-23T22:55:13Z")

</div>

My solution was to truncate the posts at 50k. It turns out they didn’t want that list anyway (a bunch of cvs reports).

I wrote code that I think saves the bad messages to files, but really, who wants 500k posts?
