void CClientMimeHandler::begin(const Item& aMimeItem) { Iterator_t lChildIter; //initialize ENVELOPE theEnvelope = mail_newenvelope (); //initialize BODY theBody = mail_newbody (); mail_initbody(theBody); //set theMessageItem lChildIter = aMimeItem.getChildren(); lChildIter->open(); // read envelope and body elements but skip non-element nodes while (lChildIter->next(theEnvelopeItem)) { if (theEnvelopeItem.getNodeKind() == store::StoreConsts::elementNode) { break; } } while (lChildIter->next(theBodyItem)) { if (theBodyItem.getNodeKind() == store::StoreConsts::elementNode) { break; } } lChildIter->close(); }
ENVELOPE* ImapClient::fetchStructure(const std::string& aHost, const std::string& aUserName, const std::string& aPassword, const std::string& aMailbox, BODY** aBody, unsigned long aMessageNumber, bool aUid, std::vector<int>& aFlagsVector) { #include "linkage.c" *aBody = mail_newbody(); MAILSTREAM* lSource = getMailStream(aHost, aUserName, aPassword, aMailbox, true); ENVELOPE * lResult = mail_fetchstructure_full (lSource, aMessageNumber, aBody, (aUid ? FT_UID : NIL)); if (!lResult) { throw EmailException("WRONG_ID", "Could not get message - wrong message id."); } if (aUid) { aMessageNumber = mail_msgno(lSource, aMessageNumber); } MESSAGECACHE* lCache = mail_elt(lSource, aMessageNumber); if (lCache->seen == 1) { aFlagsVector[0] = 1; } if (lCache->deleted == 1) { aFlagsVector[1] = 1; } if (lCache->flagged == 1) { aFlagsVector[2] = 1; } if (lCache->answered == 1) { aFlagsVector[3] = 1; } if (lCache->draft == 1) { aFlagsVector[4] = 1; } return lResult; }
BODY *create_imap_content_object(FeriteScript* script, FeriteVariable* fe_parent) { FeriteVariable *parts_list,*fe_child,*v; BODY *root,*new_body; PART *new_part,*last_part = NULL; int i=0; //Get array of child objects parts_list = ferite_hash_get( script, VAO(fe_parent)->variables->variables, "parts"); //This is true if the top level is not a multipart if( parts_list == NULL ) return( create_imap_content_leaf( script, fe_parent )); root = mail_newbody(); root->type=TYPEMULTIPART; v = ferite_hash_get( script, VAO(fe_parent)->variables->variables, "subtype"); RETURN_IF_NULL(v); if( VAS(v)->data ) root->subtype = cpystr( VAS(v)->data ); //Loop trough child array i=0; while( i < VAUA(parts_list)->size) { new_part = mail_newbody_part(); fe_child = ferite_uarray_get_index( script, VAUA(parts_list) , i ); RETURN_IF_NULL(fe_child); // Is it a multipart or a leaf? if( ferite_hash_get( script, VAO(fe_child)->variables->variables, "parts")) new_body = create_imap_content_object( script , fe_child ); else new_body = create_imap_content_leaf( script, fe_child ); RETURN_IF_NULL(new_body); new_part->body = *new_body; //Fixme, this sucks if( last_part == NULL ) root->nested.part = last_part = new_part; else last_part = last_part->next = new_part; i++; } return root; }
BODY* create_imap_content_leaf( FeriteScript *script, FeriteVariable *leaf ){ BODY *body = NULL; FeriteVariable *v = NULL; body = mail_newbody(); // fixme NULL/0 ? v = ferite_hash_get(script,VAO(leaf)->variables->variables,"encoding"); RETURN_IF_NULL(v); body->encoding=VAI(v); v = ferite_hash_get( script, VAO(leaf)->variables->variables, "content"); RETURN_IF_NULL(v); //fixme memcopy? Encode? body->contents.text.data =strdup(VAS(v)->data); body->contents.text.size =strlen(VAS(v)->data); //fixme v = ferite_hash_get( script, VAO(leaf)->variables->variables, "type" ); RETURN_IF_NULL(v); body->type=VAI(v); v = ferite_hash_get(script,VAO(leaf)->variables->variables,"subtype"); RETURN_IF_NULL(v); body->subtype=cpystr( VAS(v)->data ); v = ferite_hash_get(script,VAO(leaf)->variables->variables,"ID"); RETURN_IF_NULL(v); if( VAS(v)->length > 0 ) { body->id = cpystr( VAS(v)->data ); } v = ferite_hash_get(script,VAO(leaf)->variables->variables,"filename"); RETURN_IF_NULL(v); if( strlen(VAS(v)->data)) { PARAMETER *param = mail_newbody_parameter(); param->attribute = cpystr("filename"); param->value=cpystr( VAS(v)->data ); body->disposition.parameter = param; body->disposition.type = cpystr("attachment"); } v = ferite_hash_get( script, VAO(leaf)->variables->variables, "filepath" ); RETURN_IF_NULL(v); if( strlen(VAS(v)->data) ) { off_t size; int fd; char *buf; struct stat statinfo; fd = open(VAS(v)->data,O_RDONLY); if( fd == -1 ) { char buffer[2048]; sprintf(buffer, "Unable to create email content leaf, unable to open file: %s", VAS(v)->data); ERROR_IF_NULL(NULL, script, buffer); } size=lseek(fd,0,SEEK_END); lseek(fd,0,SEEK_SET); buf=malloc(size*sizeof(char)+1); if(buf){ read(fd,buf,size); body->contents.text.data=buf; body->contents.text.size=size; close(fd); } else{ ferite_error(script, 0, "Out of memory\n"); close(fd); return NULL; } } v = ferite_hash_get(script,VAO(leaf)->variables->variables, "charset"); RETURN_IF_NULL(v); if( strlen(VAS(v)->data) ) { PARAMETER *param = mail_newbody_parameter(); if( body->parameter ) param->next = body->parameter; body->parameter=param; body->parameter->attribute=cpystr("CHARSET"); body->parameter->value=cpystr(VAS(v)->data); } return body; }