Skip to content

Commit d8a9de3

Browse files
committed
moji.ToLF() always return nil (replace the original string directly) #72
1 parent 44c049d commit d8a9de3

File tree

6 files changed

+28
-16
lines changed

6 files changed

+28
-16
lines changed

libsisimai.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,7 @@ func Rise(path string, args *sis.DecodingArgs) (*[]sis.Fact, *[]sis.NotDecoded)
8080
notdecoded = append(notdecoded, ce)
8181
continue
8282
}
83-
mesg = moji.ToLF(mesg)
84-
fact, nyaan := sisifact.Rise(mesg, emailthing.Path, args)
83+
moji.ToLF(mesg); fact, nyaan := sisifact.Rise(mesg, emailthing.Path, args)
8584
if len(fact) > 0 { sisidigest = append(sisidigest, fact...) }
8685
if len(nyaan) > 0 { notdecoded = append(notdecoded, nyaan...) }
8786

message/rise.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ var boundaries = []string{"Content-Type: message/rfc822", "Content-Type: text/rf
3030
func Rise(mesg *string, hook sis.CfParameter0) *sis.BeforeFact {
3131
if mesg == nil || len(*mesg) < 1 { return new(sis.BeforeFact) }
3232

33-
mesg = moji.ToLF(mesg)
33+
moji.ToLF(mesg)
3434
retryagain := 0
3535
beforefact := new(sis.BeforeFact)
3636

message/sift.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func sift(bf *sis.BeforeFact, hook sis.CfParameter0) bool {
6262
if cv != nil { bf.Payload = *cv }
6363
if fe != nil && len(fe) > 0 { bf.Errors = append(bf.Errors, fe...) }
6464
}
65-
bf.Payload = *(moji.ToLF(&bf.Payload))
65+
moji.ToLF(&bf.Payload)
6666
bf.Payload = strings.ReplaceAll(bf.Payload, "\t", " ") // Replace all the TAB with " "
6767

6868
if hook != nil {

moji/11-tolf_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ func TestToLF(t *testing.T) {
1919
"nekochan\rcats\rkijitora\r\r",
2020
}
2121
for _, e := range cw {
22-
cv := ToLF(&e);
23-
cx++; if strings.Contains(*cv, "\r\n") == true { t.Errorf("%s(%s) contains CRLF", fn, *cv) }
24-
cx++; if strings.Contains(*cv, "\r") == true { t.Errorf("%s(%s) contains CR", fn, *cv) }
22+
ToLF(&e);
23+
cx++; if strings.Contains(e, "\r\n") == true { t.Errorf("%s(%s) contains CRLF", fn, e) }
24+
cx++; if strings.Contains(e, "\r") == true { t.Errorf("%s(%s) contains CR", fn, e) }
2525
}
2626
ce := "";
27-
cx++; if cv := ToLF(&ce); *cv != "" { t.Errorf("%s() returns %s", fn, *cv) }
27+
cx++; if ToLF(&ce); ce != "" { t.Errorf("%s() returns %s", fn, ce) }
2828

2929
t.Logf("The number of tests = %d", cx)
3030
}

moji/to-something.go

+19-6
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,28 @@ import "strings"
1414
// Arguments:
1515
// - argv0 (*string): Text including CR or CR/LF
1616
// Returns:
17-
// - (*string): LF converted text
17+
// - (error): Always nil
1818
func ToLF(argv0 *string) *string {
19-
if argv0 == nil || *argv0 == "" { return argv0 }
19+
if argv0 == nil || *argv0 == "" || strings.IndexByte(*argv0, '\r') < 0 { return nil }
20+
21+
readbuffer := []byte(*argv0)
22+
tolinefeed := make([]byte, 0, len(readbuffer))
23+
bytelength := len(readbuffer)
24+
25+
for j := 0; j < bytelength; j++ {
26+
// Replace '\r' and '\r\n' with '\n'
27+
if readbuffer[j] != '\r' { tolinefeed = append(tolinefeed, readbuffer[j]); continue }
28+
if j + 1 < bytelength && readbuffer[j + 1] == '\n' {
29+
// The next character is not the last character, and the next character is '\n'
30+
tolinefeed = append(tolinefeed, '\n'); j++
2031

21-
for _, e := range [2]string{"\r\n", "\r"} {
22-
// Convert CRLF and CR to LF
23-
if strings.Contains(*argv0, e) { *argv0 = strings.ReplaceAll(*argv0, e, "\n") }
32+
} else {
33+
// The next character is the last character, or the next character is not '\n'
34+
tolinefeed = append(tolinefeed, '\n')
35+
}
2436
}
25-
return argv0
37+
*argv0 = string(tolinefeed)
38+
return nil
2639
}
2740

2841
// ToPlain converts given HTML text to a plain text.

rfc2045/make-multipart-flat.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func haircut(block *string, heads bool) []string {
5555
if len(headerpart[0]) > 0 {
5656
// Append parameters
5757
headerpart[0] += " " + e
58-
headerpart[0] = moji.Squeeze(headerpart[0], ' ')
58+
moji.Squeeze(&headerpart[0], ' ')
5959
}
6060
}
6161
}
@@ -235,7 +235,7 @@ func MakeFlat(argv0 string, argv1 *string) (*string, []sis.NotDecoded) {
235235
if len(bodystring) == 0 { continue }
236236

237237
// The new-line code in the converted string is CRLF
238-
if strings.Contains(bodystring, "\r\n") { bodystring = *moji.ToLF(&bodystring) }
238+
moji.ToLF(&bodystring)
239239

240240
} else {
241241
// There is no Content-Transfer-Encoding header in the part

0 commit comments

Comments
 (0)