MCPcopy Index your code
hub / github.com/antonmedv/gitmal / parseHeaderMail

Function parseHeaderMail

pkg/gitdiff/patch_header.go:357–400  ·  view source on GitHub ↗
(mailLine string, r io.Reader, opts patchHeaderOptions)

Source from the content-addressed store, hash-verified

355}
356
357func parseHeaderMail(mailLine string, r io.Reader, opts patchHeaderOptions) (*PatchHeader, error) {
358 msg, err := mail.ReadMessage(r)
359 if err != nil {
360 return nil, err
361 }
362
363 h := &PatchHeader{}
364
365 if strings.HasPrefix(mailLine, mailHeaderPrefix) {
366 mailLine = strings.TrimPrefix(mailLine, mailHeaderPrefix)
367 if i := strings.IndexByte(mailLine, ' '); i > 0 {
368 h.SHA = mailLine[:i]
369 }
370 }
371
372 from := msg.Header.Get("From")
373 if from != "" {
374 u, err := ParsePatchIdentity(from)
375 if err != nil {
376 return nil, err
377 }
378 h.Author = &u
379 }
380
381 date := msg.Header.Get("Date")
382 if date != "" {
383 d, err := ParsePatchDate(date)
384 if err != nil {
385 return nil, err
386 }
387 h.AuthorDate = d
388 }
389
390 subject := msg.Header.Get("Subject")
391 h.SubjectPrefix, h.Title = cleanSubject(subject, opts.subjectCleanMode)
392
393 s := bufio.NewScanner(msg.Body)
394 h.Body, h.BodyAppendix = scanMessageBody(s, "", true)
395 if s.Err() != nil {
396 return nil, s.Err()
397 }
398
399 return h, nil
400}
401
402func cleanSubject(s string, mode SubjectCleanMode) (prefix string, subject string) {
403 switch mode {

Callers 1

ParsePatchHeaderFunction · 0.85

Calls 4

ParsePatchIdentityFunction · 0.85
ParsePatchDateFunction · 0.85
cleanSubjectFunction · 0.85
scanMessageBodyFunction · 0.85

Tested by

no test coverage detected