# 가져온 게시글에서 이메일 주소 제거하기

**URL:** <https://meta.discourse.org/t/removing-email-addresses-from-imported-posts/193369>\
**Category:** Product Support\
**Created:** [6월 10, 2021, 4:35오전 UTC](https://meta.discourse.org/t/removing-email-addresses-from-imported-posts/193369 "2021-06-10T04:35:38Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Mark\_Schmucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/mark_schmucker/32/124810_2.png) [@Mark\_Schmucker](https://meta.discourse.org/u/Mark_Schmucker)\
**Post date:** [6월 10, 2021, 6:10오전 UTC](https://meta.discourse.org/t/removing-email-addresses-from-imported-posts/193369/2 "2021-06-10T06:10:10Z")

</div>

@pfaffman이 우리를 위해 작성해 준 간단한 스크립트입니다. 저질스러운 부분은 제가 수정한 부분입니다. 필요하지 않을 수도 있는 몇 가지 기능이 포함되어 있는데, 예를 들어 특정 날짜 이전의 게시글에서만 이메일 주소를 제거하도록 하는 절단 날짜(cutoff date)가 있습니다.

전체적으로 제거하는 것보다 주소를 'email@removed.com’으로 대체하는 것이 가장 좋았습니다. 왜 그랬는지 기억이 나지 않지만, 주변 괄호와 더 잘 어울렸던 것 같습니다.

```plaintext
def remove_email_addresses
  n=0 
  test_mode=false 
  dt=DateTime.new(2019, 1, 1, 0, 0, 0) 
  no_emails="email@removed." 
  Post.where("raw like '%@%'").find_each do |post| 
    sleep 0.1 
    if post.created_at < dt 
      post.raw.gsub!(/[a-z0-9+-_.]+@[a-z0-9+-]+[. ,;\\]/i,no_emails) 
      if test_mode 
        puts post.raw 
        sleep 10 
      end 
      post.save unless test_mode 
      post.rebake! unless test_mode 
      puts "saved" 
      n+=1 
      puts n.to_s 
    else 
      puts "new post, leaving as-is" 
    end 
  end 
  nil 
end

> remove_email_addresses

```

---

_[View the full topic](https://meta.discourse.org/t/removing-email-addresses-from-imported-posts/193369)._
