Ejemplo n.º 1
0
func (fm *FeedMailer) mail(ch *rss.Channel, item *rss.Item) error {
	date, _ := item.ParsedPubDate()
	data := struct {
		SubjectPrefix, ChanTitle, ItemTitle string
		Date                                time.Time
		Links                               []*rss.Link
		Description                         string
		Content                             *rss.Content
	}{fm.prof.SubjectPrefix, ch.Title, item.Title, date,
		item.Links, item.Description, item.Content}

	msg := &bytes.Buffer{}
	if err := mailTemplate.Execute(msg, data); err != nil {
		return err
	}

	log.Printf("Sending e-mail: [%s] %s", ch.Title, item.Title)
	auth := smtp.PlainAuth("", fm.prof.SmtpUser, fm.prof.SmtpPass, fm.prof.SmtpHost)
	err := smtp.SendMail(fm.prof.SmtpAddr, auth, fm.prof.SrcEmail,
		fm.prof.DstEmails, msg.Bytes())
	if err != nil {
		return err
	}
	return nil
}
Ejemplo n.º 2
0
func itmify(o *rss.Item, ch *rss.Channel) Itm {
	var x Itm
	x.Title = o.Title
	x.Links = o.Links
	x.ChannelKey = ch.Key()
	x.Description = o.Description
	x.Author = o.Author
	x.Categories = o.Categories
	x.Comments = o.Comments
	x.Enclosures = o.Enclosures
	x.Guid = o.Guid
	x.PubDate = o.PubDate
	x.Id = o.Id
	x.Key = o.Key()
	x.Generator = o.Generator
	x.Contributors = o.Contributors
	x.Content = o.Content
	x.Extensions = o.Extensions
	x.Date, _ = o.ParsedPubDate()

	if o.Content != nil && o.Content.Text != "" {
		x.FullContent = o.Content.Text
	} else {
		x.FullContent = o.Description
	}

	return x
}
Ejemplo n.º 3
0
func NewItemFromRss(rssItem *rss.Item) *Item {
	description := extractDescription(rssItem)
	item := &Item{Title: rssItem.Title, Description: description}
	if len(rssItem.Links) > 0 {
		item.Url = rssItem.Links[0].Href
	}
	if publicationDate, err := rssItem.ParsedPubDate(); err != nil {
		item.PublicationDate = time.Now()
	} else {
		item.PublicationDate = publicationDate
	}
	return item
}