| 19 | } |
| 20 | |
| 21 | func (b *MessageBuilder) Extract() (title, body string, err error) { |
| 22 | content := b.Message |
| 23 | |
| 24 | if b.Edit { |
| 25 | b.editor, err = NewEditor(b.Filename, b.Title, content) |
| 26 | if err != nil { |
| 27 | return |
| 28 | } |
| 29 | for _, section := range b.commentedSections { |
| 30 | b.editor.AddCommentedSection(section) |
| 31 | } |
| 32 | content, err = b.editor.EditContent() |
| 33 | if err != nil { |
| 34 | return |
| 35 | } |
| 36 | } else { |
| 37 | nl := regexp.MustCompile(`\r?\n`) |
| 38 | content = nl.ReplaceAllString(content, "\n") |
| 39 | } |
| 40 | |
| 41 | parts := strings.SplitN(content, "\n\n", 2) |
| 42 | if len(parts) >= 1 { |
| 43 | title = strings.TrimSpace(strings.Replace(parts[0], "\n", " ", -1)) |
| 44 | } |
| 45 | if len(parts) >= 2 { |
| 46 | body = strings.TrimSpace(parts[1]) |
| 47 | } |
| 48 | |
| 49 | if title == "" { |
| 50 | defer b.Cleanup() |
| 51 | } |
| 52 | |
| 53 | return |
| 54 | } |
| 55 | |
| 56 | func (b *MessageBuilder) Cleanup() { |
| 57 | if b.editor != nil { |