# Mailing list import: posts out of order

**URL:** https://meta.discourse.org/t/mailing-list-import-posts-out-of-order/95078
**Category:** Support
**Created:** [8월 19, 2018, 2:37오전 UTC](https://meta.discourse.org/t/mailing-list-import-posts-out-of-order/95078 "2018-08-19T02:37:36Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![JonahAragon1](https://avatars.discourse-cdn.com/v4/letter/j/f19dbf/32.png) [@JonahAragon1](https://meta.discourse.org/u/JonahAragon1)
#### Post date: [8월 19, 2018, 2:37오전 UTC](https://meta.discourse.org/t/mailing-list-import-posts-out-of-order/95078/1 "2018-08-19T02:37:36Z")

</div>

I just imported all the emails from an old sympa mailing list (using the MBOX import guide), but some of the posts seem to be displayed out of order. However, the date stamps are correct, so I’m not sure why this is happening. I need to fix this over all imported threads, of which there are fairly many.

You can look at [this post](https://discourse-dev.opennic.org/t/opennic-discuss-proposal-migrating-from-sympa-to-discourse/1249/) for an example of what I’m talking about, the date stamps go Jul 7, Jul 7, Jul 9, Jul 16, Aug 1, and back to Jul 7).

Is there any command I can run to re-sort the posts by date or other suggestions?

---

<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: [8월 19, 2018, 9:34오전 UTC](https://meta.discourse.org/t/mailing-list-import-posts-out-of-order/95078/2 "2018-08-19T09:34:31Z")

</div>

There’s a rake task for sorting posts within a topic, but I do not recommend using it on more than a couple of topics as long as you still have a chance to fix the order within the import script.

```
rake posts:reorder_posts[topic_id]

```

Out of curiosity: Did you follow [Migrate a mailing list to Discourse (mbox, Listserv, Google Groups, etc)](https://meta.discourse.org/t/importing-mailing-lists-mbox-listserv-emails/79773)?  
Would you mind sending me a PM with the source of all the emails in that topic? I’d like to take a look why the import script isn’t sorting the emails correctly.

---

<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: [8월 23, 2018, 7:57오전 UTC](https://meta.discourse.org/t/mailing-list-import-posts-out-of-order/95078/3 "2018-08-23T07:57:38Z")

</div>

Thanks for the mbox file. It looks like the sorting never really worked. It must have been luck ☘ that all the mbox files I imported in the past had the correct order. 🤷‍♂️

Anyway, I fixed it in [Improve mbox import script · discourse/discourse@ac743da · GitHub](https://github.com/discourse/discourse/commit/ac743dab104d76d508a5a930c8d45f085c144ab2)

Please bear in mind that it’s still possible for some messages to be _appear_ to be in the wrong order. That’s because the post date reflects the value of the email’s `Date` header. It’s possible that the email client used the wrong date when sending an email. The import script determines the primary sort order by looking at the `In-Reply-To` and `References` header in order to prevent replies from showing up before any email it referenced.

---

<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: [8월 24, 2018, 7:57오전 UTC](https://meta.discourse.org/t/mailing-list-import-posts-out-of-order/95078/4 "2018-08-24T07:57:41Z")

</div>

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.
