forked from sendgrid/go-gmime
-
Notifications
You must be signed in to change notification settings - Fork 0
/
content_type.go
97 lines (76 loc) · 2.34 KB
/
content_type.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package gmime
/*
#cgo pkg-config: gmime-2.6
#include <stdlib.h>
#include <gmime/gmime.h>
*/
import "C"
import (
"unsafe"
)
type ContentType interface {
Janitor
Parametrized
ToString() string
MediaType() string
MediaSubtype() string
}
type rawContentType interface {
ContentType
rawContentType() *C.GMimeContentType
}
type aContentType struct {
*PointerMixin
}
func CastContentType(ct *C.GMimeContentType) ContentType {
return &aContentType{CastPointer(C.gpointer(ct))}
}
func NewContentType(ctype string, csubtype string) ContentType {
var _ctype *C.char = C.CString(ctype)
var _csubtype *C.char = C.CString(csubtype)
defer C.free(unsafe.Pointer(_ctype))
defer C.free(unsafe.Pointer(_csubtype))
ct := C.g_mime_content_type_new(_ctype, _csubtype)
defer unref(C.gpointer(ct))
return CastContentType(ct)
}
func NewContentTypeFromString(str string) ContentType {
var _str *C.char = C.CString(str)
defer C.free(unsafe.Pointer(_str))
ct := C.g_mime_content_type_new_from_string(_str)
defer unref(C.gpointer(ct))
return CastContentType(ct)
}
func (t *aContentType) ToString() string {
var contentType *C.char = C.g_mime_content_type_to_string(t.rawContentType())
defer C.free(unsafe.Pointer(contentType))
return C.GoString(contentType)
}
func (t *aContentType) MediaType() string {
var mediaType *C.char = C.g_mime_content_type_get_media_type(t.rawContentType())
return C.GoString(mediaType)
}
func (t *aContentType) MediaSubtype() string {
var mediaSubtype *C.char = C.g_mime_content_type_get_media_subtype(t.rawContentType())
return C.GoString(mediaSubtype)
}
func (t *aContentType) SetParameter(name, value string) {
var _name *C.char = C.CString(name)
var _value *C.char = C.CString(value)
defer C.free(unsafe.Pointer(_name))
defer C.free(unsafe.Pointer(_value))
C.g_mime_content_type_set_parameter(t.rawContentType(), _name, _value)
}
func (t *aContentType) Parameter(name string) string {
var _name *C.char = C.CString(name)
defer C.free(unsafe.Pointer(_name))
content := C.g_mime_content_type_get_parameter(t.rawContentType(), _name)
return C.GoString(content)
}
func (t *aContentType) ForEachParam(callback GMimeParamsCallback) {
params := C.g_mime_content_type_get_params(t.rawContentType())
forEachParam(params, callback)
}
func (t *aContentType) rawContentType() *C.GMimeContentType {
return ((*C.GMimeContentType)(t.pointer()))
}