File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -91,7 +91,6 @@ struct msg_data {
9191 char * data ;
9292 int len ;
9393 unsigned char flags ;
94- unsigned int crlf :1 ;
9594};
9695
9796static const char imap_send_usage [] = "git imap-send < <mbox>" ;
@@ -1166,6 +1165,44 @@ static int imap_make_flags(int flags, char *buf)
11661165 return d ;
11671166}
11681167
1168+ static void lf_to_crlf (struct msg_data * msg )
1169+ {
1170+ char * new ;
1171+ int i , j , lfnum = 0 ;
1172+
1173+ if (msg -> data [0 ] == '\n' )
1174+ lfnum ++ ;
1175+ for (i = 1 ; i < msg -> len ; i ++ ) {
1176+ if (msg -> data [i - 1 ] != '\r' && msg -> data [i ] == '\n' )
1177+ lfnum ++ ;
1178+ }
1179+
1180+ new = xmalloc (msg -> len + lfnum );
1181+ if (msg -> data [0 ] == '\n' ) {
1182+ new [0 ] = '\r' ;
1183+ new [1 ] = '\n' ;
1184+ i = 1 ;
1185+ j = 2 ;
1186+ } else {
1187+ new [0 ] = msg -> data [0 ];
1188+ i = 1 ;
1189+ j = 1 ;
1190+ }
1191+ for ( ; i < msg -> len ; i ++ ) {
1192+ if (msg -> data [i ] != '\n' ) {
1193+ new [j ++ ] = msg -> data [i ];
1194+ continue ;
1195+ }
1196+ if (msg -> data [i - 1 ] != '\r' )
1197+ new [j ++ ] = '\r' ;
1198+ /* otherwise it already had CR before */
1199+ new [j ++ ] = '\n' ;
1200+ }
1201+ msg -> len += lfnum ;
1202+ free (msg -> data );
1203+ msg -> data = new ;
1204+ }
1205+
11691206static int imap_store_msg (struct store * gctx , struct msg_data * data )
11701207{
11711208 struct imap_store * ctx = (struct imap_store * )gctx ;
@@ -1175,6 +1212,7 @@ static int imap_store_msg(struct store *gctx, struct msg_data *data)
11751212 int ret , d ;
11761213 char flagstr [128 ];
11771214
1215+ lf_to_crlf (data );
11781216 memset (& cb , 0 , sizeof (cb ));
11791217
11801218 cb .dlen = data -> len ;
You can’t perform that action at this time.
0 commit comments