about summary refs log tree commit diff stats
path: root/client.c
Commit message (Expand)AuthorAgeFilesLines
* added general centralization rule for new clients (works around various borke...Anselm R.Garbe2006-08-161-1/+10
* removed NUMLOCKMASK, added dynamically calculated numlockmask insteadAnselm R.Garbe2006-08-141-6/+6
* fixedAnselm R.Garbe2006-08-141-8/+4
* added some flicker preventionAnselm R.Garbe2006-08-141-1/+3
* fixed a core dumpAnselm R.Garbe2006-08-141-1/+0
* implemented restack behavior (floats are on top in tiled mode)Anselm R.Garbe2006-08-141-18/+8
* implement multi-tag selection through button3 click on the specific tagAnselm R.Garbe2006-08-111-2/+2
* applied Sander's patch as wellAnselm R.Garbe2006-08-111-2/+1
* simplified unmanageAnselm R.Garbe2006-08-111-7/+2
* removed the if(clients) check from popping codeAnselm R.Garbe2006-08-111-2/+1
* applied Sanders zoom_update patchAnselm R.Garbe2006-08-101-1/+1
* respecting inc hints in floating mode on togglemaxAnselm R.Garbe2006-08-101-1/+1
* reverting last patch, that sucks, I don't care about retarded apps like gvimAnselm R.Garbe2006-08-101-1/+1
* togglemax repects inc-hints (this way gvim can be toggle'maxed as well)Anselm R.Garbe2006-08-101-1/+1
* applied sumik's multihead patchAnselm R.Garbe2006-08-101-0/+2
* disallow zoom on maximized clientsAnselm R.Garbe2006-08-101-7/+0
* removed NET_ACTIVE_WINDOW handlingAnselm R.Garbe2006-08-081-5/+0
* implemented NET_ACTIVE_WINDOW supportAnselm R.Garbe2006-08-081-0/+5
* applied endless loop prevention on zoom()arg@10ksloc.org2006-08-071-1/+3
* small fix of the last commitarg@10ksloc.org2006-08-051-1/+1
* using -Os again, zoom is ignored in floating mode or on floating clientsarg@10ksloc.org2006-08-051-1/+1
* mouse grab needs also to grab for combinations of numlock/lockmaskarg@10ksloc.org2006-08-051-0/+20
* removed TLast tag enum, now tags is simple defined as char *[] array, the res...arg@10ksloc.org2006-08-031-1/+3
* changed Client->tags and Rule->tags to be Bool (I'll also try to remove the T...arg@10ksloc.org2006-08-031-1/+1
* made fullscreen apps working fine in floating mode (there is no sane way to m...arg@10ksloc.org2006-08-021-22/+10
* new stuffarg@10ksloc.org2006-08-021-15/+21
* implemented focus on enterwindow on titlebarsarg@10ksloc.org2006-08-021-1/+1
* reverting to old resize policyarg@10ksloc.org2006-08-021-11/+19
* new resize stuff (using XConfigureWindow instead of XSendEvent)arg@10ksloc.org2006-08-021-19/+11
* renamed WM_PROTOCOL_DELWIN into PROTODELWINarg@10ksloc.org2006-08-011-1/+1
* removed artefacts of single-linked list (thanx to Jukka, I must have been mad)arg@10ksloc.org2006-08-011-8/+3
* uppercasing all define'd values (uppercase-prefixed should only be enum field...arg@10ksloc.org2006-08-011-3/+3
* applied Sanders patchesarg@10ksloc.org2006-08-011-3/+3
* committed a patch which fixes the hints of Jukkaarg@10ksloc.org2006-08-011-34/+8
* sanitization of several clunky stuff, removed heretag (rarely of use), simpli...arg@10ksloc.org2006-07-211-2/+15
* applied sanders no_sizehints for tiled mode patch (thx!)arg@10ksloc.org2006-07-201-10/+10
* serious mistake in pop() (forgot to set c->prev to NULL on pop)arg@10ksloc.org2006-07-201-0/+1
* using double-linked list in order to get correct prev focus handlingarg@10ksloc.org2006-07-201-15/+31
* made status bar drawing more robust, implemented togglemax and togglemode, wo...arg@10ksloc.org2006-07-201-15/+38
* cleaned up codearg@10ksloc.org2006-07-201-6/+10
* removed c->f{x,y,w,h} and c->t{x,y,w,h} in favor for the new rule handling re...arg@10ksloc.org2006-07-201-76/+52
* implemented regexp matching for rulesarg@10ksloc.org2006-07-191-2/+3
* applied Jukka's patch with s/ModKeyMask/MODKEY/garg@10ksloc.org2006-07-191-3/+3
* fixed the bug mentioned by Sanderarg@10ksloc.org2006-07-191-3/+7
* refactored Sanders code somewhatarg@10ksloc.org2006-07-191-2/+2
* implemented fallback for too many clients in stacked modearg@10ksloc.org2006-07-191-2/+3
* and another fix...arg@10ksloc.org2006-07-191-1/+1
* yet another typo fixarg@10ksloc.org2006-07-191-2/+2
* fixed a typoarg@10ksloc.org2006-07-191-1/+1
* floating clients get random (x,y) offsets nowarg@10ksloc.org2006-07-191-0/+7
r/types" "github.com/mitchellh/go-homedir" notmuch "github.com/zenhack/go.notmuch" ) func init() { handlers.RegisterWorkerFactory("notmuch", NewWorker) } var errUnsupported = fmt.Errorf("unsupported command") type worker struct { w *types.Worker pathToDB string db *notmuch.DB selected *notmuch.Query uidStore *uidstore.Store excludedTags []string nameQueryMap map[string]string } // NewWorker creates a new maildir worker with the provided worker. func NewWorker(w *types.Worker) (types.Backend, error) { return &worker{w: w}, nil } // Run starts the worker's message handling loop. func (w *worker) Run() { for { action := <-w.w.Actions msg := w.w.ProcessAction(action) if err := w.handleMessage(msg); err == errUnsupported { w.w.PostMessage(&types.Unsupported{ Message: types.RespondTo(msg), }, nil) } else if err != nil { w.w.PostMessage(&types.Error{ Message: types.RespondTo(msg), Error: err, }, nil) } } } func (w *worker) done(msg types.WorkerMessage) { w.w.PostMessage(&types.Done{types.RespondTo(msg)}, nil) } func (w *worker) err(msg types.WorkerMessage, err error) { w.w.PostMessage(&types.Error{ Message: types.RespondTo(msg), Error: err, }, nil) } func (w *worker) handleMessage(msg types.WorkerMessage) error { switch msg := msg.(type) { case *types.Unsupported: // No-op case *types.Configure: return w.handleConfigure(msg) case *types.Connect: return w.handleConnect(msg) case *types.ListDirectories: return w.handleListDirectories(msg) case *types.OpenDirectory: return w.handleOpenDirectory(msg) case *types.FetchDirectoryContents: return w.handleFetchDirectoryContents(msg) case *types.FetchMessageHeaders: return w.handleFetchMessageHeaders(msg) case *types.FetchMessageBodyPart: return w.handleFetchMessageBodyPart(msg) case *types.FetchFullMessages: return w.handleFetchFullMessages(msg) case *types.ReadMessages: return w.handleReadMessages(msg) // TODO // return w.handleSearchDirectory(msg) // case *types.DeleteMessages: // not implemented, they are generally not used // in a notmuch based workflow // case *types.CopyMessages: // return w.handleCopyMessages(msg) // case *types.AppendMessage: // return w.handleAppendMessage(msg) // case *types.CreateDirectory: // return w.handleCreateDirectory(msg) } return errUnsupported } func (w *worker) handleConfigure(msg *types.Configure) error { u, err := url.Parse(msg.Config.Source) if err != nil { w.w.Logger.Printf("error configuring notmuch worker: %v", err) return err } home, err := homedir.Expand(u.Hostname()) if err != nil { return fmt.Errorf("could not resolve home directory: %v", err) } w.pathToDB = filepath.Join(home, u.Path) w.uidStore = uidstore.NewStore() if err = w.loadQueryMap(msg.Config); err != nil { return fmt.Errorf("could not load query map: %v", err) } if err = w.loadExcludeTags(msg.Config); err != nil { return fmt.Errorf("could not load excluded tags: %v", err) } w.w.Logger.Printf("configured db directory: %s", w.pathToDB) return nil } func (w *worker) handleConnect(msg *types.Connect) error { var err error w.db, err = notmuch.Open(w.pathToDB, notmuch.DBReadWrite) if err != nil { return fmt.Errorf("could not connect to notmuch db: %v", err) } w.done(msg) return nil } func (w *worker) handleListDirectories(msg *types.ListDirectories) error { for name := range w.nameQueryMap { w.w.PostMessage(&types.Directory{ Message: types.RespondTo(msg), Dir: &models.Directory{ Name: name, Attributes: []string{}, }, }, nil) } w.done(msg) return nil } func (w *worker) handleOpenDirectory(msg *types.OpenDirectory) error { w.w.Logger.Printf("opening %s", msg.Directory) // try the friendly name first, if that fails assume it's a query query, ok := w.nameQueryMap[msg.Directory] if !ok { query = msg.Directory } w.selected = w.db.NewQuery(query) w.selected.SetExcludeScheme(notmuch.EXCLUDE_TRUE) w.selected.SetSortScheme(notmuch.SORT_OLDEST_FIRST) for _, t := range w.excludedTags { err := w.selected.AddTagExclude(t) if err != nil && err != notmuch.ErrIgnored { return err } } //TODO: why does this need to be sent twice?? info := &types.DirectoryInfo{ Info: &models.DirectoryInfo{ Name: msg.Directory, Flags: []string{}, ReadOnly: false, // total messages Exists: w.selected.CountMessages(), // new messages since mailbox was last opened Recent: 0, // total unread Unseen: 0, }, } w.w.PostMessage(info, nil) w.w.PostMessage(info, nil) w.done(msg) return nil } func (w *worker) handleFetchDirectoryContents( msg *types.FetchDirectoryContents) error { uids, err := w.uidsFromQuery(w.selected) if err != nil { w.w.Logger.Printf("error scanning uids: %v", err) return err } w.w.PostMessage(&types.DirectoryContents{ Message: types.RespondTo(msg), Uids: uids, }, nil) w.done(msg) return nil } func (w *worker) handleFetchMessageHeaders( msg *types.FetchMessageHeaders) error { for _, uid := range msg.Uids { m, err := w.msgFromUid(uid) if err != nil { w.w.Logger.Printf("could not get message: %v", err) w.err(msg, err) continue } info, err := m.MessageInfo() if err != nil { w.w.Logger.Printf("could not get message info: %v", err) w.err(msg, err) continue } w.w.PostMessage(&types.MessageInfo{ Message: types.RespondTo(msg), Info: info, }, nil) } w.done(msg) return nil } func (w *worker) uidsFromQuery(query *notmuch.Query) ([]uint32, error) { msgs, err := query.Messages() if err != nil { return nil, err } var msg *notmuch.Message var uids []uint32 for msgs.Next(&msg) { uid := w.uidStore.GetOrInsert(msg.ID()) uids = append(uids, uid) } return uids, nil } func (w *worker) msgFromUid(uid uint32) (*Message, error) { key, ok := w.uidStore.GetKey(uid) if !ok { return nil, fmt.Errorf("Invalid uid: %v", uid) } nm, err := w.db.FindMessage(key) if err != nil { return nil, fmt.Errorf("Could not fetch message for key %q: %v", key, err) } msg := &Message{ key: key, uid: uid, msg: nm, } return msg, nil } func (w *worker) handleFetchMessageBodyPart( msg *types.FetchMessageBodyPart) error { m, err := w.msgFromUid(msg.Uid) if err != nil { w.w.Logger.Printf("could not get message %d: %v", msg.Uid, err) return err } r, err := m.NewBodyPartReader(msg.Part) if err != nil { w.w.Logger.Printf( "could not get body part reader for message=%d, parts=%#v: %v", msg.Uid, msg.Part, err) return err } w.w.PostMessage(&types.MessageBodyPart{ Message: types.RespondTo(msg), Part: &models.MessageBodyPart{ Reader: r, Uid: msg.Uid, }, }, nil) if err := m.MarkRead(true); err != nil { w.w.Logger.Printf("could not mark message as read: %v", err) return err } // send updated flags to ui info, err := m.MessageInfo() if err != nil { w.w.Logger.Printf("could not fetch message info: %v", err) return err } w.w.PostMessage(&types.MessageInfo{ Message: types.RespondTo(msg), Info: info, }, nil) w.done(msg) return nil } func (w *worker) handleFetchFullMessages(msg *types.FetchFullMessages) error { for _, uid := range msg.Uids { m, err := w.msgFromUid(uid) if err != nil { w.w.Logger.Printf("could not get message %d: %v", uid, err) return err } r, err := m.NewReader() if err != nil { w.w.Logger.Printf("could not get message reader: %v", err) return err } w.w.PostMessage(&types.FullMessage{ Message: types.RespondTo(msg), Content: &models.FullMessage{ Uid: uid, Reader: r, }, }, nil) } w.done(msg) return nil } func (w *worker) handleReadMessages(msg *types.ReadMessages) error { for _, uid := range msg.Uids { m, err := w.msgFromUid(uid) if err != nil { w.w.Logger.Printf("could not get message: %v", err) w.err(msg, err) continue } if err := m.MarkRead(msg.Read); err != nil { w.w.Logger.Printf("could not mark message as read: %v", err) w.err(msg, err) continue } info, err := m.MessageInfo() if err != nil { w.w.Logger.Printf("could not get message info: %v", err) w.err(msg, err) continue } w.w.PostMessage(&types.MessageInfo{ Message: types.RespondTo(msg), Info: info, }, nil) } w.done(msg) return nil } func (w *worker) loadQueryMap(acctConfig *config.AccountConfig) error { raw, ok := acctConfig.Params["query-map"] if !ok { // nothing to do return nil } file, err := homedir.Expand(raw) if err != nil { return err } f, err := os.Open(file) if err != nil { return err } defer f.Close() w.nameQueryMap = make(map[string]string) scanner := bufio.NewScanner(f) for scanner.Scan() { line := scanner.Text() split := strings.SplitN(line, "=", 2) if len(split) != 2 { return fmt.Errorf("invalid line %q, want name=query", line) } w.nameQueryMap[split[0]] = split[1] } return nil } func (w *worker) loadExcludeTags(acctConfig *config.AccountConfig) error { raw, ok := acctConfig.Params["exclude-tags"] if !ok { // nothing to do return nil } w.excludedTags = strings.Split(raw, ",") return nil }