Ejemplo n.º 1
0
/* Add a new message to the given notmuch database.
 *
 * Here,'filename' should be a path relative to the path of
 * 'database' (see notmuch_database_get_path), or else should be an
 * absolute filename with initial components that match the path of
 * 'database'.
 *
 * The file should be a single mail message (not a multi-message mbox)
 * that is expected to remain at its current location, (since the
 * notmuch database will reference the filename, and will not copy the
 * entire contents of the file.
 *
 * If 'message' is not NULL, then, on successful return '*message'
 * will be initialized to a message object that can be used for things
 * such as adding tags to the just-added message. The user should call
 * notmuch_message_destroy when done with the message. On any failure
 * '*message' will be set to NULL.
 *
 * Return value:
 *
 * NOTMUCH_STATUS_SUCCESS: Message successfully added to database.
 *
 * NOTMUCH_STATUS_XAPIAN_EXCEPTION: A Xapian exception occurred,
 *	message not added.
 *
 * NOTMUCH_STATUS_DUPLICATE_MESSAGE_ID: Message has the same message
 *	ID as another message already in the database. The new
 *	filename was successfully added to the message in the database
 *	(if not already present).
 *
 * NOTMUCH_STATUS_FILE_ERROR: an error occurred trying to open the
 *	file, (such as permission denied, or file not found,
 *	etc.). Nothing added to the database.
 *
 * NOTMUCH_STATUS_FILE_NOT_EMAIL: the contents of filename don't look
 *	like an email message. Nothing added to the database.
 *
 * NOTMUCH_STATUS_READ_ONLY_DATABASE: Database was opened in read-only
 *	mode so no message can be added.
 */
func (self *Database) AddMessage(fname string) (*Message, Status) {
	var c_fname *C.char = C.CString(fname)
	defer C.free(unsafe.Pointer(c_fname))

	if c_fname == nil {
		return nil, STATUS_OUT_OF_MEMORY
	}

	var c_msg *C.notmuch_message_t = new(C.notmuch_message_t)
	st := Status(C.notmuch_database_add_message(self.db, c_fname, &c_msg))

	return &Message{message: c_msg}, st
}
Ejemplo n.º 2
0
Archivo: db.go Proyecto: gmuch/gmuch
// AddMessage adds a new message to the current database or associate an
// additional filename with an existing message.
func (db *DB) AddMessage(filename string) (*Message, error) {
	cfilename := C.CString(filename)
	defer C.free(unsafe.Pointer(cfilename))

	var cmsg *C.notmuch_message_t
	if err := statusErr(C.notmuch_database_add_message(db.toC(), cfilename, &cmsg)); err != nil {
		return nil, err
	}
	msg := &Message{
		cptr:   unsafe.Pointer(cmsg),
		parent: (*cStruct)(db),
	}
	setGcClose(msg)
	return msg, nil
}