}
int main(int argc, char** argv) {
+ if(argc < 4){
+ return 1;
+ }
W3_Library_Init();
+ struct W3* w3 = W3_Create("pop3", argv[1], 110);
+ W3_POP3_Set_Username(w3, argv[2]);
+ W3_POP3_Set_Password(w3, argv[3]);
+ W3_Set_Method(w3, "LIST");
+ W3_Send_Request(w3);
}
if(redir != NULL) free(redir);
}
-void W3_Enable_Redirect(struct W3* w3) { __W3_Add_Prop(w3, "HTTP_REDIRECT"); }
+void W3_Enable_Redirect(struct W3* w3) { __W3_Add_Prop(w3, "HTTP_REDIRECT", "YES"); }
#include <stdlib.h>
#include <string.h>
+#include <stdbool.h>
-void __W3_POP3_Request(struct W3* w3) {}
+void __W3_POP3_Request(struct W3* w3) {
+ if(__W3_Get_Prop(w3, "POP3_USERNAME") == NULL || __W3_Get_Prop(w3, "POP3_PASSWORD") == NULL){
+ __W3_Debug("LibW3-POP3", "Set the username/password");
+ return;
+ }
+ char* buf = malloc(w3->readsize);
+ int phase = 0;
+ int login = 0;
+ while(true) {
+ int len = __W3_Auto_Read(w3, buf, w3->readsize);
+ if(len <= 0) break;
+ int i;
+ for(i = 0; i < len; i++){
+ write(1, buf + i, 1);
+ char c = buf[i];
+ if(c == '\r') continue;
+ if(c == '\n'){
+ if(login == 0){
+ char* str = __W3_Concat3("USER ", __W3_Get_Prop(w3, "POP3_USERNAME"), "\r\n");
+ __W3_Auto_Write(w3, str, strlen(str));
+ free(str);
+ login = 1;
+ }else if(login == 1){
+ char* str = __W3_Concat3("PASS ", __W3_Get_Prop(w3, "POP3_PASSWORD"), "\r\n");
+ __W3_Auto_Write(w3, str, strlen(str));
+ free(str);
+ login = 2;
+ }else{
+ if(phase == 3){
+ /* OK */
+ if(login == 2){
+ /* Login success */
+ login = 3;
+ }else{
+ }
+ }else if(phase == 4){
+ /* ERR */
+ if(login == 2){
+ /* Login failed */
+ login = 0;
+ }else{
+ }
+ }
+ }
+ phase = 0;
+ continue;
+ }
+ if(phase == 0){
+ if(c == '+'){
+ phase = 1;
+ }else if(c == '-'){
+ phase = 2;
+ }
+ }else if(phase == 1){
+ if(c == ' ') phase += 2;
+ }
+ }
+ }
+ free(buf);
+}
+
+void W3_POP3_Set_Username(struct W3* w3, const char* username){
+ __W3_Add_Prop(w3, "POP3_USERNAME", username);
+}
+
+
+void W3_POP3_Set_Password(struct W3* w3, const char* password){
+ __W3_Add_Prop(w3, "POP3_PASSWORD", password);
+}
bool __W3_Have_Prop(struct W3* w3, const char* name) {
if(w3->props == NULL) return false;
int i;
- for(i = 0; w3->props[i] != NULL; i++) {
+ for(i = 0; w3->props[i] != NULL; i += 2) {
if(strcmp(w3->props[i], name) == 0) return true;
}
return false;
}
-void __W3_Add_Prop(struct W3* w3, const char* name) {
+
+char* __W3_Get_Prop(struct W3* w3, const char* name){
+ if(w3->props == NULL) return NULL;
+ int i;
+ for(i = 0; w3->props[i] != NULL; i += 2) {
+ if(strcmp(w3->props[i], name) == 0) return w3->props[i + 1];
+ }
+ return NULL;
+
+}
+
+void __W3_Add_Prop(struct W3* w3, const char* name, const char* value) {
char* str = __W3_Concat3("Adding a prop `", name, "`");
__W3_Debug("Prop", str);
free(str);
int len = 0;
if(w3->props == NULL) {
- w3->props = malloc(sizeof(*w3->props) * 2);
+ w3->props = malloc(sizeof(*w3->props) * 3);
} else {
char** oldprops = w3->props;
for(len = 0; oldprops[len] != NULL; len++)
;
- w3->props = malloc(sizeof(*w3->props) * (len + 2));
+ w3->props = malloc(sizeof(*w3->props) * (len + 3));
for(len = 0; oldprops[len] != NULL; len++) {
w3->props[len] = oldprops[len];
}
free(oldprops);
}
w3->props[len] = __W3_Strdup(name);
- w3->props[len + 1] = NULL;
+ w3->props[len + 1] = __W3_Strdup(value);
+ w3->props[len + 2] = NULL;
}
#include "W3Core.h"
void __W3_POP3_Request(struct W3* w3);
+void W3_POP3_Set_Username(struct W3* w3, const char* username);
+void W3_POP3_Set_Password(struct W3* w3, const char* password);
#ifdef __cplusplus
}
unsigned long __W3_Auto_Read(struct W3* w3, char* data, unsigned long length);
bool __W3_Have_Header(struct W3* w3, const char* name);
bool __W3_Have_Prop(struct W3* w3, const char* name);
-void __W3_Add_Prop(struct W3* w3, const char* name);
+void __W3_Add_Prop(struct W3* w3, const char* name, const char* value);
+char* __W3_Get_Prop(struct W3* w3, const char* name);
void* __W3_Get_Event(struct W3* w3, const char* eventname);
char* __W3_Get_Platform(void);