@@ -134,9 +134,7 @@ pub async fn connect<A: ToSocketAddrs, S: AsRef<str>>(
134
134
let _greeting = match client. read_response ( ) . await {
135
135
Some ( greeting) => greeting,
136
136
None => {
137
- return Err ( Error :: Bad ( format ! (
138
- "could not read server Greeting after connect"
139
- ) ) ) ;
137
+ return Err ( Error :: Bad ( "could not read server Greeting after connect" ) ) ;
140
138
}
141
139
} ;
142
140
@@ -1142,28 +1140,32 @@ impl<T: Read + Write + Unpin + fmt::Debug> Session<T> {
1142
1140
/// failing that, a `CHECK` command) after one or more `APPEND` commands.
1143
1141
pub async fn append < S : AsRef < str > , B : AsRef < [ u8 ] > > (
1144
1142
& mut self ,
1145
- _mailbox : S ,
1146
- _content : B ,
1143
+ mailbox : S ,
1144
+ content : B ,
1147
1145
) -> Result < ( ) > {
1148
- unimplemented ! ( ) ;
1149
- // let content = content.as_ref();
1150
- // self.run_command(&format!(
1151
- // "APPEND \"{}\" {{{}}}",
1152
- // mailbox.as_ref(),
1153
- // content.len()
1154
- // ))
1155
- // .await?;
1156
- // let mut v = Vec::new();
1157
- // self.readline(&mut v).await?;
1158
- // if !v.starts_with(b"+") {
1159
- // return Err(Error::Append);
1160
- // }
1161
- // self.stream.write_all(content).await?;
1162
- // self.stream.write_all(b"\r\n").await?;
1163
- // self.stream.flush().await?;
1164
- // self.read_response().await?;
1165
-
1166
- // Ok(())
1146
+ let content = content. as_ref ( ) ;
1147
+ self . run_command ( & format ! (
1148
+ "APPEND \" {}\" {{{}}}" ,
1149
+ mailbox. as_ref( ) ,
1150
+ content. len( )
1151
+ ) )
1152
+ . await ?;
1153
+
1154
+ match self . read_response ( ) . await {
1155
+ Some ( Ok ( res) ) => {
1156
+ if let Response :: Continue { .. } = res. parsed ( ) {
1157
+ self . stream . as_mut ( ) . write_all ( content) . await ?;
1158
+ self . stream . as_mut ( ) . write_all ( b"\r \n " ) . await ?;
1159
+ self . stream . flush ( ) . await ?;
1160
+ self . read_response ( ) . await . transpose ( ) ?;
1161
+ Ok ( ( ) )
1162
+ } else {
1163
+ Err ( Error :: Append )
1164
+ }
1165
+ }
1166
+ Some ( Err ( err) ) => Err ( err. into ( ) ) ,
1167
+ _ => Err ( Error :: Append ) ,
1168
+ }
1167
1169
}
1168
1170
1169
1171
/// The [`SEARCH` command](https://tools.ietf.org/html/rfc3501#section-6.4.4) searches the
@@ -1286,8 +1288,7 @@ impl<T: Read + Write + Unpin + fmt::Debug> Connection<T> {
1286
1288
self . stream
1287
1289
. encode ( Request ( None , command. as_bytes ( ) . into ( ) ) )
1288
1290
. await ?;
1289
- // TODO
1290
- // self.stream.flush().await?;
1291
+ self . stream . flush ( ) . await ?;
1291
1292
Ok ( ( ) )
1292
1293
}
1293
1294
@@ -1296,8 +1297,7 @@ impl<T: Read + Write + Unpin + fmt::Debug> Connection<T> {
1296
1297
self . stream
1297
1298
. encode ( Request ( Some ( request_id. clone ( ) ) , command. as_bytes ( ) . into ( ) ) )
1298
1299
. await ?;
1299
- // TODO
1300
- // self.stream.flush().await?;
1300
+ self . stream . flush ( ) . await ?;
1301
1301
Ok ( request_id)
1302
1302
}
1303
1303
@@ -1823,32 +1823,28 @@ mod tests {
1823
1823
1824
1824
#[ async_attributes:: test]
1825
1825
async fn store ( ) {
1826
- generic_store ( " " , |c, set, query| {
1827
- async move {
1828
- c. lock ( )
1829
- . await
1830
- . store ( set, query)
1831
- . await ?
1832
- . collect :: < Vec < _ > > ( )
1833
- . await ;
1834
- Ok ( ( ) )
1835
- }
1826
+ generic_store ( " " , |c, set, query| async move {
1827
+ c. lock ( )
1828
+ . await
1829
+ . store ( set, query)
1830
+ . await ?
1831
+ . collect :: < Vec < _ > > ( )
1832
+ . await ;
1833
+ Ok ( ( ) )
1836
1834
} )
1837
1835
. await ;
1838
1836
}
1839
1837
1840
1838
#[ async_attributes:: test]
1841
1839
async fn uid_store ( ) {
1842
- generic_store ( " UID " , |c, set, query| {
1843
- async move {
1844
- c. lock ( )
1845
- . await
1846
- . uid_store ( set, query)
1847
- . await ?
1848
- . collect :: < Vec < _ > > ( )
1849
- . await ;
1850
- Ok ( ( ) )
1851
- }
1840
+ generic_store ( " UID " , |c, set, query| async move {
1841
+ c. lock ( )
1842
+ . await
1843
+ . uid_store ( set, query)
1844
+ . await ?
1845
+ . collect :: < Vec < _ > > ( )
1846
+ . await ;
1847
+ Ok ( ( ) )
1852
1848
} )
1853
1849
. await ;
1854
1850
}
@@ -1868,22 +1864,18 @@ mod tests {
1868
1864
1869
1865
#[ async_attributes:: test]
1870
1866
async fn copy ( ) {
1871
- generic_copy ( " " , |c, set, query| {
1872
- async move {
1873
- c. lock ( ) . await . copy ( set, query) . await ?;
1874
- Ok ( ( ) )
1875
- }
1867
+ generic_copy ( " " , |c, set, query| async move {
1868
+ c. lock ( ) . await . copy ( set, query) . await ?;
1869
+ Ok ( ( ) )
1876
1870
} )
1877
1871
. await ;
1878
1872
}
1879
1873
1880
1874
#[ async_attributes:: test]
1881
1875
async fn uid_copy ( ) {
1882
- generic_copy ( " UID " , |c, set, query| {
1883
- async move {
1884
- c. lock ( ) . await . uid_copy ( set, query) . await ?;
1885
- Ok ( ( ) )
1886
- }
1876
+ generic_copy ( " UID " , |c, set, query| async move {
1877
+ c. lock ( ) . await . uid_copy ( set, query) . await ?;
1878
+ Ok ( ( ) )
1887
1879
} )
1888
1880
. await ;
1889
1881
}
@@ -1942,33 +1934,29 @@ mod tests {
1942
1934
1943
1935
#[ async_attributes:: test]
1944
1936
async fn fetch ( ) {
1945
- generic_fetch ( " " , |c, seq, query| {
1946
- async move {
1947
- c. lock ( )
1948
- . await
1949
- . fetch ( seq, query)
1950
- . await ?
1951
- . collect :: < Vec < _ > > ( )
1952
- . await ;
1953
-
1954
- Ok ( ( ) )
1955
- }
1937
+ generic_fetch ( " " , |c, seq, query| async move {
1938
+ c. lock ( )
1939
+ . await
1940
+ . fetch ( seq, query)
1941
+ . await ?
1942
+ . collect :: < Vec < _ > > ( )
1943
+ . await ;
1944
+
1945
+ Ok ( ( ) )
1956
1946
} )
1957
1947
. await ;
1958
1948
}
1959
1949
1960
1950
#[ async_attributes:: test]
1961
1951
async fn uid_fetch ( ) {
1962
- generic_fetch ( " UID " , |c, seq, query| {
1963
- async move {
1964
- c. lock ( )
1965
- . await
1966
- . uid_fetch ( seq, query)
1967
- . await ?
1968
- . collect :: < Vec < _ > > ( )
1969
- . await ;
1970
- Ok ( ( ) )
1971
- }
1952
+ generic_fetch ( " UID " , |c, seq, query| async move {
1953
+ c. lock ( )
1954
+ . await
1955
+ . uid_fetch ( seq, query)
1956
+ . await ?
1957
+ . collect :: < Vec < _ > > ( )
1958
+ . await ;
1959
+ Ok ( ( ) )
1972
1960
} )
1973
1961
. await ;
1974
1962
}
0 commit comments