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>" ;
@@ -1162,6 +1161,44 @@ static int imap_make_flags(int flags, char *buf)
11621161 return d ;
11631162}
11641163
1164+ static void lf_to_crlf (struct msg_data * msg )
1165+ {
1166+ char * new ;
1167+ int i , j , lfnum = 0 ;
1168+
1169+ if (msg -> data [0 ] == '\n' )
1170+ lfnum ++ ;
1171+ for (i = 1 ; i < msg -> len ; i ++ ) {
1172+ if (msg -> data [i - 1 ] != '\r' && msg -> data [i ] == '\n' )
1173+ lfnum ++ ;
1174+ }
1175+
1176+ new = xmalloc (msg -> len + lfnum );
1177+ if (msg -> data [0 ] == '\n' ) {
1178+ new [0 ] = '\r' ;
1179+ new [1 ] = '\n' ;
1180+ i = 1 ;
1181+ j = 2 ;
1182+ } else {
1183+ new [0 ] = msg -> data [0 ];
1184+ i = 1 ;
1185+ j = 1 ;
1186+ }
1187+ for ( ; i < msg -> len ; i ++ ) {
1188+ if (msg -> data [i ] != '\n' ) {
1189+ new [j ++ ] = msg -> data [i ];
1190+ continue ;
1191+ }
1192+ if (msg -> data [i - 1 ] != '\r' )
1193+ new [j ++ ] = '\r' ;
1194+ /* otherwise it already had CR before */
1195+ new [j ++ ] = '\n' ;
1196+ }
1197+ msg -> len += lfnum ;
1198+ free (msg -> data );
1199+ msg -> data = new ;
1200+ }
1201+
11651202static int imap_store_msg (struct store * gctx , struct msg_data * data )
11661203{
11671204 struct imap_store * ctx = (struct imap_store * )gctx ;
@@ -1171,6 +1208,7 @@ static int imap_store_msg(struct store *gctx, struct msg_data *data)
11711208 int ret , d ;
11721209 char flagstr [128 ];
11731210
1211+ lf_to_crlf (data );
11741212 memset (& cb , 0 , sizeof (cb ));
11751213
11761214 cb .dlen = data -> len ;
You can’t perform that action at this time.
0 commit comments